listctrl.h 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/listctrl.h
  3. // Purpose: interface of wxListCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /// style flags
  8. #define wxLC_VRULES 0x0001
  9. #define wxLC_HRULES 0x0002
  10. #define wxLC_ICON 0x0004
  11. #define wxLC_SMALL_ICON 0x0008
  12. #define wxLC_LIST 0x0010
  13. #define wxLC_REPORT 0x0020
  14. #define wxLC_ALIGN_TOP 0x0040
  15. #define wxLC_ALIGN_LEFT 0x0080
  16. #define wxLC_AUTOARRANGE 0x0100
  17. #define wxLC_VIRTUAL 0x0200
  18. #define wxLC_EDIT_LABELS 0x0400
  19. #define wxLC_NO_HEADER 0x0800
  20. #define wxLC_NO_SORT_HEADER 0x1000
  21. #define wxLC_SINGLE_SEL 0x2000
  22. #define wxLC_SORT_ASCENDING 0x4000
  23. #define wxLC_SORT_DESCENDING 0x8000
  24. #define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
  25. #define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
  26. #define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
  27. /// Mask flags to tell app/GUI what fields of wxListItem are valid
  28. #define wxLIST_MASK_STATE 0x0001
  29. #define wxLIST_MASK_TEXT 0x0002
  30. #define wxLIST_MASK_IMAGE 0x0004
  31. #define wxLIST_MASK_DATA 0x0008
  32. #define wxLIST_SET_ITEM 0x0010
  33. #define wxLIST_MASK_WIDTH 0x0020
  34. #define wxLIST_MASK_FORMAT 0x0040
  35. /// State flags for indicating the state of an item
  36. #define wxLIST_STATE_DONTCARE 0x0000
  37. #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
  38. #define wxLIST_STATE_FOCUSED 0x0002
  39. #define wxLIST_STATE_SELECTED 0x0004
  40. #define wxLIST_STATE_CUT 0x0008 // MSW only
  41. #define wxLIST_STATE_DISABLED 0x0010 // OS2 only
  42. #define wxLIST_STATE_FILTERED 0x0020 // OS2 only
  43. #define wxLIST_STATE_INUSE 0x0040 // OS2 only
  44. #define wxLIST_STATE_PICKED 0x0080 // OS2 only
  45. #define wxLIST_STATE_SOURCE 0x0100 // OS2 only
  46. /// Hit test flags, used in HitTest
  47. #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
  48. #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
  49. #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
  50. #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
  51. #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
  52. #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
  53. #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
  54. #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
  55. #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
  56. #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
  57. /// GetSubItemRect constants
  58. #define wxLIST_GETSUBITEMRECT_WHOLEITEM -1l
  59. /// Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
  60. enum
  61. {
  62. wxLIST_NEXT_ABOVE, // Searches for an item above the specified item
  63. wxLIST_NEXT_ALL, // Searches for subsequent item by index
  64. wxLIST_NEXT_BELOW, // Searches for an item below the specified item
  65. wxLIST_NEXT_LEFT, // Searches for an item to the left of the specified item
  66. wxLIST_NEXT_RIGHT // Searches for an item to the right of the specified item
  67. };
  68. /// Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
  69. enum
  70. {
  71. wxLIST_ALIGN_DEFAULT,
  72. wxLIST_ALIGN_LEFT,
  73. wxLIST_ALIGN_TOP,
  74. wxLIST_ALIGN_SNAP_TO_GRID
  75. };
  76. /// Column format (MSW only except wxLIST_FORMAT_LEFT)
  77. enum wxListColumnFormat
  78. {
  79. wxLIST_FORMAT_LEFT,
  80. wxLIST_FORMAT_RIGHT,
  81. wxLIST_FORMAT_CENTRE,
  82. wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
  83. };
  84. /// Autosize values for SetColumnWidth
  85. enum
  86. {
  87. wxLIST_AUTOSIZE = -1,
  88. wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
  89. };
  90. /// Flag values for GetItemRect
  91. enum
  92. {
  93. wxLIST_RECT_BOUNDS,
  94. wxLIST_RECT_ICON,
  95. wxLIST_RECT_LABEL
  96. };
  97. /// Flag values for FindItem (MSW only)
  98. enum
  99. {
  100. wxLIST_FIND_UP,
  101. wxLIST_FIND_DOWN,
  102. wxLIST_FIND_LEFT,
  103. wxLIST_FIND_RIGHT
  104. };
  105. /**
  106. @class wxListCtrl
  107. A list control presents lists in a number of formats: list view, report view,
  108. icon view and small icon view. In any case, elements are numbered from zero.
  109. For all these modes, the items are stored in the control and must be added to
  110. it using wxListCtrl::InsertItem method.
  111. A special case of report view quite different from the other modes of the list
  112. control is a virtual control in which the items data (including text, images
  113. and attributes) is managed by the main program and is requested by the control
  114. itself only when needed which allows to have controls with millions of items
  115. without consuming much memory. To use virtual list control you must use
  116. wxListCtrl::SetItemCount first and override at least wxListCtrl::OnGetItemText
  117. (and optionally wxListCtrl::OnGetItemImage or wxListCtrl::OnGetItemColumnImage and
  118. wxListCtrl::OnGetItemAttr) to return the information about the items when the
  119. control requests it.
  120. Virtual list control can be used as a normal one except that no operations
  121. which can take time proportional to the number of items in the control happen
  122. -- this is required to allow having a practically infinite number of items.
  123. For example, in a multiple selection virtual list control, the selections won't
  124. be sent when many items are selected at once because this could mean iterating
  125. over all the items.
  126. Using many of wxListCtrl features is shown in the
  127. @ref page_samples_listctrl "corresponding sample".
  128. To intercept events from a list control, use the event table macros described
  129. in wxListEvent.
  130. <b>wxMac Note</b>: Starting with wxWidgets 2.8, wxListCtrl uses a native
  131. implementation for report mode, and uses a generic implementation for other
  132. modes. You can use the generic implementation for report mode as well by setting
  133. the @c mac.listctrl.always_use_generic system option (see wxSystemOptions) to 1.
  134. @beginStyleTable
  135. @style{wxLC_LIST}
  136. Multicolumn list view, with optional small icons. Columns are
  137. computed automatically, i.e. you don't set columns as in
  138. @c wxLC_REPORT. In other words, the list wraps, unlike a wxListBox.
  139. @style{wxLC_REPORT}
  140. Single or multicolumn report view, with optional header.
  141. @style{wxLC_VIRTUAL}
  142. The application provides items text on demand. May only be used
  143. with @c wxLC_REPORT.
  144. @style{wxLC_ICON}
  145. Large icon view, with optional labels.
  146. @style{wxLC_SMALL_ICON}
  147. Small icon view, with optional labels.
  148. @style{wxLC_ALIGN_TOP}
  149. Icons align to the top. Win32 default, Win32 only.
  150. @style{wxLC_ALIGN_LEFT}
  151. Icons align to the left.
  152. @style{wxLC_AUTOARRANGE}
  153. Icons arrange themselves. Win32 only.
  154. @style{wxLC_EDIT_LABELS}
  155. Labels are editable: the application will be notified when editing
  156. starts.
  157. @style{wxLC_NO_HEADER}
  158. No header in report mode.
  159. @style{wxLC_SINGLE_SEL}
  160. Single selection (default is multiple).
  161. @style{wxLC_SORT_ASCENDING}
  162. Sort in ascending order. (You must still supply a comparison callback
  163. in wxListCtrl::SortItems.)
  164. @style{wxLC_SORT_DESCENDING}
  165. Sort in descending order. (You must still supply a comparison callback
  166. in wxListCtrl::SortItems.)
  167. @style{wxLC_HRULES}
  168. Draws light horizontal rules between rows in report mode.
  169. @style{wxLC_VRULES}
  170. Draws light vertical rules between columns in report mode.
  171. @endStyleTable
  172. @beginEventEmissionTable{wxListEvent}
  173. @event{EVT_LIST_BEGIN_DRAG(id, func)}
  174. Begin dragging with the left mouse button.
  175. Processes a @c wxEVT_LIST_BEGIN_DRAG event type.
  176. @event{EVT_LIST_BEGIN_RDRAG(id, func)}
  177. Begin dragging with the right mouse button.
  178. Processes a @c wxEVT_LIST_BEGIN_RDRAG event type.
  179. @event{EVT_BEGIN_LABEL_EDIT(id, func)}
  180. Begin editing a label. This can be prevented by calling Veto().
  181. Processes a @c wxEVT_LIST_BEGIN_LABEL_EDIT event type.
  182. @event{EVT_LIST_END_LABEL_EDIT(id, func)}
  183. Finish editing a label. This can be prevented by calling Veto().
  184. Processes a @c wxEVT_LIST_END_LABEL_EDIT event type.
  185. @event{EVT_LIST_DELETE_ITEM(id, func)}
  186. An item was deleted.
  187. Processes a @c wxEVT_LIST_DELETE_ITEM event type.
  188. @event{EVT_LIST_DELETE_ALL_ITEMS(id, func)}
  189. All items were deleted.
  190. Processes a @c wxEVT_LIST_DELETE_ALL_ITEMS event type.
  191. @event{EVT_LIST_ITEM_SELECTED(id, func)}
  192. The item has been selected.
  193. Processes a @c wxEVT_LIST_ITEM_SELECTED event type.
  194. @event{EVT_LIST_ITEM_DESELECTED(id, func)}
  195. The item has been deselected.
  196. Processes a @c wxEVT_LIST_ITEM_DESELECTED event type.
  197. @event{EVT_LIST_ITEM_ACTIVATED(id, func)}
  198. The item has been activated (ENTER or double click).
  199. Processes a @c wxEVT_LIST_ITEM_ACTIVATED event type.
  200. @event{EVT_LIST_ITEM_FOCUSED(id, func)}
  201. The currently focused item has changed.
  202. Processes a @c wxEVT_LIST_ITEM_FOCUSED event type.
  203. @event{EVT_LIST_ITEM_MIDDLE_CLICK(id, func)}
  204. The middle mouse button has been clicked on an item. This is
  205. only supported by the generic control.
  206. Processes a @c wxEVT_LIST_ITEM_MIDDLE_CLICK event type.
  207. @event{EVT_LIST_ITEM_RIGHT_CLICK(id, func)}
  208. The right mouse button has been clicked on an item.
  209. Processes a @c wxEVT_LIST_ITEM_RIGHT_CLICK event type.
  210. @event{EVT_LIST_KEY_DOWN(id, func)}
  211. A key has been pressed.
  212. Processes a @c wxEVT_LIST_KEY_DOWN event type.
  213. @event{EVT_LIST_INSERT_ITEM(id, func)}
  214. An item has been inserted.
  215. Processes a @c wxEVT_LIST_INSERT_ITEM event type.
  216. @event{EVT_LIST_COL_CLICK(id, func)}
  217. A column (m_col) has been left-clicked.
  218. Processes a @c wxEVT_LIST_COL_CLICK event type.
  219. @event{EVT_LIST_COL_RIGHT_CLICK(id, func)}
  220. A column (m_col) has been right-clicked.
  221. Processes a @c wxEVT_LIST_COL_RIGHT_CLICK event type.
  222. @event{EVT_LIST_COL_BEGIN_DRAG(id, func)}
  223. The user started resizing a column - can be vetoed.
  224. Processes a @c wxEVT_LIST_COL_BEGIN_DRAG event type.
  225. @event{EVT_LIST_COL_DRAGGING(id, func)}
  226. The divider between columns is being dragged.
  227. Processes a @c wxEVT_LIST_COL_DRAGGING event type.
  228. @event{EVT_LIST_COL_END_DRAG(id, func)}
  229. A column has been resized by the user.
  230. Processes a @c wxEVT_LIST_COL_END_DRAG event type.
  231. @event{EVT_LIST_CACHE_HINT(id, func)}
  232. Prepare cache for a virtual list control.
  233. Processes a @c wxEVT_LIST_CACHE_HINT event type.
  234. @endEventTable
  235. @library{wxcore}
  236. @category{ctrl}
  237. @appearance{listctrl}
  238. @see @ref overview_listctrl, wxListView, wxListBox, wxTreeCtrl, wxImageList,
  239. wxListEvent, wxListItem, wxEditableListBox
  240. */
  241. class wxListCtrl : public wxControl
  242. {
  243. public:
  244. /**
  245. Default constructor.
  246. */
  247. wxListCtrl();
  248. /**
  249. Constructor, creating and showing a list control.
  250. @param parent
  251. Parent window. Must not be @NULL.
  252. @param id
  253. Window identifier. The value wxID_ANY indicates a default value.
  254. @param pos
  255. Window position.
  256. If ::wxDefaultPosition is specified then a default position is chosen.
  257. @param size
  258. Window size.
  259. If ::wxDefaultSize is specified then the window is sized appropriately.
  260. @param style
  261. Window style. See wxListCtrl.
  262. @param validator
  263. Window validator.
  264. @param name
  265. Window name.
  266. @see Create(), wxValidator
  267. */
  268. wxListCtrl(wxWindow* parent, wxWindowID id,
  269. const wxPoint& pos = wxDefaultPosition,
  270. const wxSize& size = wxDefaultSize,
  271. long style = wxLC_ICON,
  272. const wxValidator& validator = wxDefaultValidator,
  273. const wxString& name = wxListCtrlNameStr);
  274. /**
  275. Destructor, destroying the list control.
  276. */
  277. virtual ~wxListCtrl();
  278. /**
  279. Adds a new column to the list control in report view mode.
  280. This is just a convenient wrapper for InsertColumn() which adds the new
  281. column after all the existing ones without having to specify its
  282. position explicitly.
  283. @since 2.9.4
  284. */
  285. long AppendColumn(const wxString& heading,
  286. wxListColumnFormat format = wxLIST_FORMAT_LEFT,
  287. int width = -1);
  288. /**
  289. Arranges the items in icon or small icon view.
  290. This only has effect on Win32. @a flag is one of:
  291. - wxLIST_ALIGN_DEFAULT: Default alignment.
  292. - wxLIST_ALIGN_LEFT: Align to the left side of the control.
  293. - wxLIST_ALIGN_TOP: Align to the top side of the control.
  294. - wxLIST_ALIGN_SNAP_TO_GRID: Snap to grid.
  295. */
  296. bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
  297. /**
  298. Sets the image list associated with the control and takes ownership of it
  299. (i.e. the control will, unlike when using SetImageList(), delete the list
  300. when destroyed). @a which is one of @c wxIMAGE_LIST_NORMAL, @c wxIMAGE_LIST_SMALL,
  301. @c wxIMAGE_LIST_STATE (the last is unimplemented).
  302. @see SetImageList()
  303. */
  304. void AssignImageList(wxImageList* imageList, int which);
  305. /**
  306. Deletes all items and all columns.
  307. @note This sends an event of type @c wxEVT_LIST_DELETE_ALL_ITEMS
  308. under all platforms.
  309. */
  310. void ClearAll();
  311. /**
  312. Creates the list control. See wxListCtrl() for further details.
  313. */
  314. bool Create(wxWindow* parent, wxWindowID id,
  315. const wxPoint& pos = wxDefaultPosition,
  316. const wxSize& size = wxDefaultSize,
  317. long style = wxLC_ICON,
  318. const wxValidator& validator = wxDefaultValidator,
  319. const wxString& name = wxListCtrlNameStr);
  320. /**
  321. Deletes all items in the list control.
  322. This function does @e not send the @c wxEVT_LIST_DELETE_ITEM
  323. event because deleting many items from the control would be too slow
  324. then (unlike wxListCtrl::DeleteItem) but it does send the special @c
  325. wxEVT_LIST_DELETE_ALL_ITEMS event if the control was not empty.
  326. If it was already empty, nothing is done and no event is sent.
  327. @return @true if the items were successfully deleted or if the control
  328. was already empty, @false if an error occurred while deleting the
  329. items.
  330. */
  331. bool DeleteAllItems();
  332. /**
  333. Deletes a column.
  334. */
  335. bool DeleteColumn(int col);
  336. /**
  337. Deletes the specified item.
  338. This function sends the @c wxEVT_LIST_DELETE_ITEM event for the
  339. item being deleted.
  340. @see DeleteAllItems()
  341. */
  342. bool DeleteItem(long item);
  343. /**
  344. Starts editing the label of the given item.
  345. This function generates a @c EVT_LIST_BEGIN_LABEL_EDIT event which can be
  346. vetoed so that no text control will appear for in-place editing.
  347. If the user changed the label (i.e. s/he does not press ESC or leave
  348. the text control without changes, a @c EVT_LIST_END_LABEL_EDIT event
  349. will be sent which can be vetoed as well.
  350. */
  351. wxTextCtrl* EditLabel(long item,
  352. wxClassInfo* textControlClass = wxCLASSINFO(wxTextCtrl));
  353. /**
  354. Enable alternating row background colours (also called zebra striping).
  355. This method can only be called for the control in virtual report mode,
  356. i.e. having ::wxLC_REPORT and ::wxLC_VIRTUAL styles.
  357. When enabling alternating colours, the appropriate colour for the even
  358. rows is chosen automatically depending on the default foreground and
  359. background colours which are used for the odd rows.
  360. @param enable
  361. If @true, enable alternating row background colours, i.e. different
  362. colours for the odd and even rows. If @false, disable this feature
  363. and use the same background colour for all rows.
  364. @since 2.9.5
  365. @see SetAlternateRowColour()
  366. */
  367. void EnableAlternateRowColours(bool enable = true);
  368. /**
  369. Enable or disable a beep if there is no match for the currently
  370. entered text when searching for the item from keyboard.
  371. The default is to not beep in this case except in wxMSW where the
  372. beep is always generated by the native control and cannot be disabled,
  373. i.e. calls to this function do nothing there.
  374. @since 2.9.5
  375. */
  376. void EnableBellOnNoMatch(bool on = true);
  377. /**
  378. Finish editing the label.
  379. This method allows to programmatically end editing a list control item
  380. in place. Usually it will only be called when editing is in progress,
  381. i.e. if GetEditControl() returns non-NULL. In particular, do not call
  382. it from EVT_LIST_BEGIN_LABEL_EDIT handler as the edit control is not
  383. yet fully created by then, just veto the event in this handler instead
  384. to prevent the editing from even starting.
  385. Notice that calling this method will result in EVT_LIST_END_LABEL_EDIT
  386. event being generated.
  387. Currently only implemented in wxMSW.
  388. @param cancel If @true, discard the changes made by user, as if @c
  389. Escape key was pressed. Otherwise, accept the changes as if @c
  390. Return was pressed.
  391. @return @true if item editing was finished or @false if no item as
  392. being edited.
  393. */
  394. bool EndEditLabel(bool cancel);
  395. /**
  396. Ensures this item is visible.
  397. */
  398. bool EnsureVisible(long item);
  399. /**
  400. Find an item whose label matches this string, starting from start or the
  401. beginning if start is @c -1. The string comparison is case insensitive.
  402. If @a partial is @true then this method will look for items which begin with @a str.
  403. @return The next matching item if any or @c -1 (wxNOT_FOUND) otherwise.
  404. */
  405. long FindItem(long start, const wxString& str,
  406. bool partial = false);
  407. /**
  408. Find an item whose data matches this data, starting from start or the
  409. beginning if 'start' is @c -1.
  410. @beginWxPerlOnly
  411. In wxPerl this method is implemented as FindItemData(start, data).
  412. @endWxPerlOnly
  413. @return The next matching item if any or @c -1 (wxNOT_FOUND) otherwise.
  414. */
  415. long FindItem(long start, wxUIntPtr data);
  416. /**
  417. Find an item nearest this position in the specified direction,
  418. starting from @a start or the beginning if @a start is -1.
  419. @beginWxPerlOnly
  420. In wxPerl this method is implemented as FindItemAtPos(start, pt, direction).
  421. @endWxPerlOnly
  422. @return The next matching item if any or @c -1 (wxNOT_FOUND) otherwise.
  423. */
  424. long FindItem(long start, const wxPoint& pt, int direction);
  425. /**
  426. Gets information about this column.
  427. See SetItem() for more information.
  428. @beginWxPerlOnly
  429. In wxPerl this method takes only the @a col parameter and
  430. returns a @c Wx::ListItem (or @c undef).
  431. @endWxPerlOnly
  432. */
  433. bool GetColumn(int col, wxListItem& item) const;
  434. /**
  435. Returns the number of columns.
  436. */
  437. int GetColumnCount() const;
  438. /**
  439. Gets the column index from its position in visual order.
  440. After calling SetColumnsOrder(), the index returned by this function
  441. corresponds to the value of the element number @a pos in the array
  442. returned by GetColumnsOrder().
  443. Please see SetColumnsOrder() documentation for an example and
  444. additional remarks about the columns ordering.
  445. @see GetColumnOrder()
  446. */
  447. int GetColumnIndexFromOrder(int pos) const;
  448. /**
  449. Gets the column visual order position.
  450. This function returns the index of the column which appears at the
  451. given visual position, e.g. calling it with @a col equal to 0 returns
  452. the index of the first shown column.
  453. Please see SetColumnsOrder() documentation for an example and
  454. additional remarks about the columns ordering.
  455. @see GetColumnsOrder(), GetColumnIndexFromOrder()
  456. */
  457. int GetColumnOrder(int col) const;
  458. /**
  459. Gets the column width (report view only).
  460. */
  461. int GetColumnWidth(int col) const;
  462. /**
  463. Returns the array containing the orders of all columns.
  464. On error, an empty array is returned.
  465. Please see SetColumnsOrder() documentation for an example and
  466. additional remarks about the columns ordering.
  467. @see GetColumnOrder(), GetColumnIndexFromOrder()
  468. */
  469. wxArrayInt GetColumnsOrder() const;
  470. /**
  471. Gets the number of items that can fit vertically in the visible area of
  472. the list control (list or report view) or the total number of items in
  473. the list control (icon or small icon view).
  474. */
  475. int GetCountPerPage() const;
  476. /**
  477. Returns the edit control being currently used to edit a label.
  478. Returns @NULL if no label is being edited.
  479. @note It is currently only implemented for wxMSW and the generic version,
  480. not for the native Mac OS X version.
  481. */
  482. wxTextCtrl* GetEditControl() const;
  483. /**
  484. Returns the specified image list. @a which may be one of:
  485. - wxIMAGE_LIST_NORMAL: The normal (large icon) image list.
  486. - wxIMAGE_LIST_SMALL: The small icon image list.
  487. - wxIMAGE_LIST_STATE: The user-defined state image list (unimplemented).
  488. */
  489. wxImageList* GetImageList(int which) const;
  490. /**
  491. Gets information about the item. See SetItem() for more information.
  492. You must call @e info.SetId() to set the ID of item you're interested in
  493. before calling this method, and @e info.SetMask() with the flags indicating
  494. what fields you need to retrieve from @a info.
  495. @beginWxPerlOnly
  496. In wxPerl this method takes as parameter the ID of the item
  497. and (optionally) the column, and returns a Wx::ListItem object.
  498. @endWxPerlOnly
  499. */
  500. bool GetItem(wxListItem& info) const;
  501. /**
  502. Returns the colour for this item.
  503. If the item has no specific colour, returns an invalid colour
  504. (and not the default background control of the control itself).
  505. @see GetItemTextColour()
  506. */
  507. wxColour GetItemBackgroundColour(long item) const;
  508. /**
  509. Returns the number of items in the list control.
  510. */
  511. int GetItemCount() const;
  512. /**
  513. Gets the application-defined data associated with this item.
  514. */
  515. wxUIntPtr GetItemData(long item) const;
  516. /**
  517. Returns the item's font.
  518. */
  519. wxFont GetItemFont(long item) const;
  520. /**
  521. Returns the position of the item, in icon or small icon view.
  522. @beginWxPerlOnly
  523. In wxPerl this method takes only the @a item parameter and
  524. returns a @c Wx::Point (or @c undef).
  525. @endWxPerlOnly
  526. */
  527. bool GetItemPosition(long item, wxPoint& pos) const;
  528. /**
  529. Returns the rectangle representing the item's size and position, in physical
  530. coordinates.
  531. @a code is one of wxLIST_RECT_BOUNDS, wxLIST_RECT_ICON, wxLIST_RECT_LABEL.
  532. @beginWxPerlOnly
  533. In wxPerl this method takes only the @a item and @a code parameters and
  534. returns a @c Wx::Rect (or @c undef).
  535. @endWxPerlOnly
  536. */
  537. bool GetItemRect(long item, wxRect& rect,
  538. int code = wxLIST_RECT_BOUNDS) const;
  539. /**
  540. Retrieves the spacing between icons in pixels: horizontal spacing is
  541. returned as @c x component of the wxSize object and the vertical spacing
  542. as its @c y component.
  543. */
  544. wxSize GetItemSpacing() const;
  545. /**
  546. Gets the item state. For a list of state flags, see SetItem().
  547. The @a stateMask indicates which state flags are of interest.
  548. */
  549. int GetItemState(long item, long stateMask) const;
  550. /**
  551. Gets the item text for this item.
  552. @param item
  553. Item (zero-based) index.
  554. @param col
  555. Item column (zero-based) index. Column 0 is the default. This
  556. parameter is new in wxWidgets 2.9.1.
  557. */
  558. wxString GetItemText(long item, int col = 0) const;
  559. /**
  560. Returns the colour for this item.
  561. If the item has no specific colour, returns an invalid colour (and not the
  562. default foreground control of the control itself as this wouldn't allow
  563. distinguishing between items having the same colour as the current control
  564. foreground and items with default colour which, hence, have always the
  565. same colour as the control).
  566. */
  567. wxColour GetItemTextColour(long item) const;
  568. /**
  569. Searches for an item with the given geometry or state, starting from
  570. @a item but excluding the @a item itself.
  571. If @a item is -1, the first item that matches the specified flags will be returned.
  572. Returns the first item with given state following @a item or -1 if no such item found.
  573. This function may be used to find all selected items in the control like this:
  574. @code
  575. long item = -1;
  576. for ( ;; )
  577. {
  578. item = listctrl->GetNextItem(item,
  579. wxLIST_NEXT_ALL,
  580. wxLIST_STATE_SELECTED);
  581. if ( item == -1 )
  582. break;
  583. // this item is selected - do whatever is needed with it
  584. wxLogMessage("Item %ld is selected.", item);
  585. }
  586. @endcode
  587. @a geometry can be one of:
  588. - wxLIST_NEXT_ABOVE: Searches for an item above the specified item.
  589. - wxLIST_NEXT_ALL: Searches for subsequent item by index.
  590. - wxLIST_NEXT_BELOW: Searches for an item below the specified item.
  591. - wxLIST_NEXT_LEFT: Searches for an item to the left of the specified item.
  592. - wxLIST_NEXT_RIGHT: Searches for an item to the right of the specified item.
  593. @note this parameter is only supported by wxMSW currently and ignored on
  594. other platforms.
  595. @a state can be a bitlist of the following:
  596. - wxLIST_STATE_DONTCARE: Don't care what the state is.
  597. - wxLIST_STATE_DROPHILITED: The item indicates it is a drop target.
  598. - wxLIST_STATE_FOCUSED: The item has the focus.
  599. - wxLIST_STATE_SELECTED: The item is selected.
  600. - wxLIST_STATE_CUT: The item is selected as part of a cut and paste operation.
  601. */
  602. long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL,
  603. int state = wxLIST_STATE_DONTCARE) const;
  604. /**
  605. Returns the number of selected items in the list control.
  606. */
  607. int GetSelectedItemCount() const;
  608. /**
  609. Returns the rectangle representing the size and position, in physical
  610. coordinates, of the given subitem, i.e. the part of the row @a item in the
  611. column @a subItem.
  612. This method is only meaningful when the wxListCtrl is in the report mode.
  613. If @a subItem parameter is equal to the special value
  614. @c wxLIST_GETSUBITEMRECT_WHOLEITEM the return value is the same as
  615. for GetItemRect().
  616. @a code can be one of @c wxLIST_RECT_BOUNDS, @c wxLIST_RECT_ICON or
  617. @c wxLIST_RECT_LABEL.
  618. @since 2.7.0
  619. */
  620. bool GetSubItemRect(long item, long subItem, wxRect& rect,
  621. int code = wxLIST_RECT_BOUNDS) const;
  622. /**
  623. Gets the text colour of the list control.
  624. */
  625. wxColour GetTextColour() const;
  626. /**
  627. Gets the index of the topmost visible item when in list or report view.
  628. */
  629. long GetTopItem() const;
  630. /**
  631. Returns the rectangle taken by all items in the control. In other words, if the
  632. controls client size were equal to the size of this rectangle, no scrollbars
  633. would be needed and no free space would be left.
  634. Note that this function only works in the icon and small icon views, not in
  635. list or report views (this is a limitation of the native Win32 control).
  636. */
  637. wxRect GetViewRect() const;
  638. /**
  639. Set the alternative row background colour to a specific colour.
  640. It is recommended to call EnableAlternateRowColours() instead of using
  641. these methods as native implementations of this control might support
  642. alternating row colours but not setting the exact colour to be used for
  643. them.
  644. As EnableAlternateRowColours(), this method can only be used with
  645. controls having ::wxLC_REPORT and ::wxLC_VIRTUAL styles.
  646. @param colour
  647. A valid alternative row background colour to enable alternating
  648. rows or invalid colour to disable them and use the same colour for
  649. all rows.
  650. @since 2.9.5
  651. */
  652. void SetAlternateRowColour(const wxColour& colour);
  653. /**
  654. Determines which item (if any) is at the specified point, giving details
  655. in @a flags. Returns index of the item or @c wxNOT_FOUND if no item is at
  656. the specified point.
  657. @a flags will be a combination of the following flags:
  658. - wxLIST_HITTEST_ABOVE: Above the client area.
  659. - wxLIST_HITTEST_BELOW: Below the client area.
  660. - wxLIST_HITTEST_NOWHERE: In the client area but below the last item.
  661. - wxLIST_HITTEST_ONITEMICON: On the bitmap associated with an item.
  662. - wxLIST_HITTEST_ONITEMLABEL: On the label (string) associated with an item.
  663. - wxLIST_HITTEST_ONITEMRIGHT: In the area to the right of an item.
  664. - wxLIST_HITTEST_ONITEMSTATEICON: On the state icon for a tree view item
  665. that is in a user-defined state.
  666. - wxLIST_HITTEST_TOLEFT: To the right of the client area.
  667. - wxLIST_HITTEST_TORIGHT: To the left of the client area.
  668. - wxLIST_HITTEST_ONITEM: Combination of @c wxLIST_HITTEST_ONITEMICON,
  669. @c wxLIST_HITTEST_ONITEMLABEL, @c wxLIST_HITTEST_ONITEMSTATEICON.
  670. If @a ptrSubItem is not @NULL and the wxListCtrl is in the report
  671. mode the subitem (or column) number will also be provided.
  672. This feature is only available in version 2.7.0 or higher and is currently only
  673. implemented under wxMSW and requires at least comctl32.dll of version 4.70 on
  674. the host system or the value stored in @a ptrSubItem will be always -1.
  675. To compile this feature into wxWidgets library you need to have access to
  676. commctrl.h of version 4.70 that is provided by Microsoft.
  677. @beginWxPerlOnly
  678. In wxPerl this method only takes the @a point parameter
  679. and returns a 2-element list (item, flags).
  680. @endWxPerlOnly
  681. */
  682. long HitTest(const wxPoint& point, int& flags, long* ptrSubItem = NULL) const;
  683. /**
  684. Returns true if the control is currently using ::wxLC_REPORT style.
  685. */
  686. bool InReportView() const;
  687. /**
  688. For report view mode (only), inserts a column.
  689. For more details, see SetItem(). Also see InsertColumn(long, const
  690. wxString&, int, int) overload for a usually more convenient
  691. alternative to this method and the description of how the item width
  692. is interpreted by this method.
  693. */
  694. long InsertColumn(long col, const wxListItem& info);
  695. /**
  696. For report view mode (only), inserts a column.
  697. Insert a new column in the list control in report view mode at the
  698. given position specifying its most common attributes.
  699. Notice that to set the image for the column you need to use
  700. Insert(long, const wxListItem&) overload and specify ::wxLIST_MASK_IMAGE
  701. in the item mask.
  702. @param col
  703. The index where the column should be inserted. Valid indices are
  704. from 0 up to GetColumnCount() inclusive and the latter can be used
  705. to append the new column after the last existing one.
  706. @param heading
  707. The string specifying the column heading.
  708. @param format
  709. The flags specifying the control heading text alignment.
  710. @param width
  711. If positive, the width of the column in pixels. Otherwise it can be
  712. @c wxLIST_AUTOSIZE to choose the default size for the column or @c
  713. wxLIST_AUTOSIZE_USEHEADER to fit the column width to @a heading or
  714. to extend to fill all the remaining space for the last column.
  715. Notice that in case of @c wxLIST_AUTOSIZE fixed width is used as
  716. there are no items in this column to use for determining its best
  717. size yet. If you want to fit the column to its contents, use
  718. SetColumnWidth() after adding the items with values in this column.
  719. @return
  720. The index of the inserted column or -1 if adding it failed.
  721. */
  722. long InsertColumn(long col, const wxString& heading,
  723. int format = wxLIST_FORMAT_LEFT,
  724. int width = wxLIST_AUTOSIZE);
  725. /**
  726. Inserts an item, returning the index of the new item if successful, -1 otherwise.
  727. @param info
  728. wxListItem object
  729. */
  730. long InsertItem(wxListItem& info);
  731. /**
  732. Insert an string item.
  733. @param index
  734. Index of the new item, supplied by the application
  735. @param label
  736. String label
  737. @beginWxPerlOnly
  738. In wxPerl this method is implemented as InsertStringItem(index, label).
  739. @endWxPerlOnly
  740. */
  741. long InsertItem(long index, const wxString& label);
  742. /**
  743. Insert an image item.
  744. @param index
  745. Index of the new item, supplied by the application
  746. @param imageIndex
  747. Index into the image list associated with this control and view style
  748. @beginWxPerlOnly
  749. In wxPerl this method is implemented as InsertImageItem(index, imageIndex).
  750. @endWxPerlOnly
  751. */
  752. long InsertItem(long index, int imageIndex);
  753. /**
  754. Insert an image/string item.
  755. @param index
  756. Index of the new item, supplied by the application
  757. @param label
  758. String label
  759. @param imageIndex
  760. Index into the image list associated with this control and view style
  761. @beginWxPerlOnly
  762. In wxPerl this method is implemented as InsertImageStringItem(index, label, imageIndex).
  763. @endWxPerlOnly
  764. */
  765. long InsertItem(long index, const wxString& label,
  766. int imageIndex);
  767. /**
  768. Returns true if the control is currently in virtual report view.
  769. */
  770. bool IsVirtual() const;
  771. /**
  772. Redraws the given @e item.
  773. This is only useful for the virtual list controls as without calling this
  774. function the displayed value of the item doesn't change even when the
  775. underlying data does change.
  776. @see RefreshItems()
  777. */
  778. void RefreshItem(long item);
  779. /**
  780. Redraws the items between @a itemFrom and @e itemTo.
  781. The starting item must be less than or equal to the ending one.
  782. Just as RefreshItem() this is only useful for virtual list controls.
  783. */
  784. void RefreshItems(long itemFrom, long itemTo);
  785. /**
  786. Scrolls the list control. If in icon, small icon or report view mode,
  787. @a dx specifies the number of pixels to scroll. If in list view mode,
  788. @a dx specifies the number of columns to scroll. @a dy always specifies
  789. the number of pixels to scroll vertically.
  790. @note This method is currently only implemented in the Windows version.
  791. */
  792. bool ScrollList(int dx, int dy);
  793. /**
  794. Sets the background colour.
  795. Note that the wxWindow::GetBackgroundColour() function of wxWindow base
  796. class can be used to retrieve the current background colour.
  797. */
  798. virtual bool SetBackgroundColour(const wxColour& col);
  799. /**
  800. Sets information about this column.
  801. See SetItem() for more information.
  802. */
  803. bool SetColumn(int col, wxListItem& item);
  804. /**
  805. Sets the column width.
  806. @a width can be a width in pixels or @c wxLIST_AUTOSIZE (-1) or
  807. @c wxLIST_AUTOSIZE_USEHEADER (-2).
  808. @c wxLIST_AUTOSIZE will resize the column to the length of its longest item.
  809. @c wxLIST_AUTOSIZE_USEHEADER will resize the column to the length of the
  810. header (Win32) or 80 pixels (other platforms).
  811. In small or normal icon view, @a col must be -1, and the column width is set
  812. for all columns.
  813. */
  814. bool SetColumnWidth(int col, int width);
  815. /**
  816. Changes the order in which the columns are shown.
  817. By default, the columns of a list control appear on the screen in order
  818. of their indices, i.e. the column 0 appears first, the column 1 next
  819. and so on. However by using this function it is possible to arbitrarily
  820. reorder the columns visual order and the user can also rearrange the
  821. columns interactively by dragging them. In this case, the index of the
  822. column is not the same as its order and the functions GetColumnOrder()
  823. and GetColumnIndexFromOrder() should be used to translate between them.
  824. Notice that all the other functions still work with the column indices,
  825. i.e. the visual positioning of the columns on screen doesn't affect the
  826. code setting or getting their values for example.
  827. The @a orders array must have the same number elements as the number of
  828. columns and contain each position exactly once. Its n-th element
  829. contains the index of the column to be shown in n-th position, so for a
  830. control with three columns passing an array with elements 2, 0 and 1
  831. results in the third column being displayed first, the first one next
  832. and the second one last.
  833. Example of using it:
  834. @code
  835. wxListCtrl *list = new wxListCtrl(...);
  836. for ( int i = 0; i < 3; i++ )
  837. list->InsertColumn(i, wxString::Format("Column %d", i));
  838. wxArrayInt order(3);
  839. order[0] = 2;
  840. order[1] = 0;
  841. order[2] = 1;
  842. list->SetColumnsOrder(order);
  843. // now list->GetColumnsOrder() will return order and
  844. // list->GetColumnIndexFromOrder(n) will return order[n] and
  845. // list->GetColumnOrder() will return 1, 2 and 0 for the column 0,
  846. // 1 and 2 respectively
  847. @endcode
  848. Please notice that this function makes sense for report view only and
  849. currently is only implemented in wxMSW port. To avoid explicit tests
  850. for @c __WXMSW__ in your code, please use @c wxHAS_LISTCTRL_COLUMN_ORDER
  851. as this will allow it to start working under the other platforms when
  852. support for the column reordering is added there.
  853. @see GetColumnsOrder()
  854. */
  855. bool SetColumnsOrder(const wxArrayInt& orders);
  856. /**
  857. Sets the image list associated with the control.
  858. @a which is one of @c wxIMAGE_LIST_NORMAL, @c wxIMAGE_LIST_SMALL,
  859. @c wxIMAGE_LIST_STATE (the last is unimplemented).
  860. This method does not take ownership of the image list, you have to
  861. delete it yourself.
  862. @see AssignImageList()
  863. */
  864. void SetImageList(wxImageList* imageList, int which);
  865. /**
  866. Sets the data of an item.
  867. Using the wxListItem's mask and state mask, you can change only selected
  868. attributes of a wxListCtrl item.
  869. */
  870. bool SetItem(wxListItem& info);
  871. /**
  872. Sets an item string field at a particular column.
  873. */
  874. long SetItem(long index, int column, const wxString& label, int imageId = -1);
  875. /**
  876. Sets the background colour for this item.
  877. This function only works in report view mode.
  878. The colour can be retrieved using GetItemBackgroundColour().
  879. */
  880. void SetItemBackgroundColour(long item, const wxColour& col);
  881. /**
  882. Sets the image associated with the item.
  883. In report view, you can specify the column.
  884. The image is an index into the image list associated with the list control.
  885. */
  886. bool SetItemColumnImage(long item, long column, int image);
  887. /**
  888. This method can only be used with virtual list controls.
  889. It is used to indicate to the control the number of items it contains.
  890. After calling it, the main program should be ready to handle calls to
  891. various item callbacks (such as wxListCtrl::OnGetItemText) for all
  892. items in the range from 0 to @a count.
  893. Notice that the control is not necessarily redrawn after this call as
  894. it may be undesirable if an item which is not visible on the screen
  895. anyhow was added to or removed from a control displaying many items, if
  896. you do need to refresh the display you can just call Refresh() manually.
  897. */
  898. void SetItemCount(long count);
  899. /**
  900. Associates application-defined data with this item.
  901. Notice that this function cannot be used to associate pointers with the control
  902. items, use SetItemPtrData() instead.
  903. */
  904. bool SetItemData(long item, long data);
  905. /**
  906. Sets the item's font.
  907. */
  908. void SetItemFont(long item, const wxFont& font);
  909. /**
  910. Sets the unselected and selected images associated with the item.
  911. The images are indices into the image list associated with the list control.
  912. */
  913. bool SetItemImage(long item, int image, int selImage = -1);
  914. /**
  915. Sets the position of the item, in icon or small icon view. Windows only.
  916. */
  917. bool SetItemPosition(long item, const wxPoint& pos);
  918. /**
  919. Associates application-defined data with this item.
  920. The @a data parameter may be either an integer or a pointer cast to the
  921. @c wxUIntPtr type which is guaranteed to be large enough to be able to
  922. contain all integer types and pointers.
  923. @since 2.8.4
  924. */
  925. bool SetItemPtrData(long item, wxUIntPtr data);
  926. /**
  927. Sets the item state.
  928. The @a stateMask is a combination of @c wxLIST_STATE_XXX constants
  929. described in wxListItem documentation. For each of the bits specified
  930. in @a stateMask, the corresponding state is set or cleared depending on
  931. whether @a state argument contains the same bit or not.
  932. So to select an item you can use
  933. @code
  934. list->SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
  935. @endcode
  936. while to deselect it you should use
  937. @code
  938. list->SetItemState(item, 0, wxLIST_STATE_SELECTED);
  939. @endcode
  940. Consider using wxListView if possible to avoid dealing with this
  941. error-prone and confusing method.
  942. */
  943. bool SetItemState(long item, long state, long stateMask);
  944. /**
  945. Sets the item text for this item.
  946. */
  947. void SetItemText(long item, const wxString& text);
  948. /**
  949. Sets the colour for this item.
  950. This function only works in report view.
  951. The colour can be retrieved using GetItemTextColour().
  952. */
  953. void SetItemTextColour(long item, const wxColour& col);
  954. /**
  955. Adds or removes a single window style.
  956. */
  957. void SetSingleStyle(long style, bool add = true);
  958. /**
  959. Sets the text colour of the list control.
  960. */
  961. void SetTextColour(const wxColour& col);
  962. /**
  963. Sets the whole window style, deleting all items.
  964. */
  965. void SetWindowStyleFlag(long style);
  966. /**
  967. Call this function to sort the items in the list control. Sorting is done
  968. using the specified @a fnSortCallBack function. This function must have the
  969. following prototype:
  970. @code
  971. int wxCALLBACK wxListCompareFunction(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
  972. @endcode
  973. It is called each time when the two items must be compared and should return 0
  974. if the items are equal, negative value if the first item is less than the
  975. second one and positive value if the first one is greater than the second one
  976. (the same convention as used by @c qsort(3)).
  977. The parameter @e item1 is the client data associated with the first item (NOT the index).
  978. The parameter @e item2 is the client data associated with the second item (NOT the index).
  979. The parameter @e data is the value passed to SortItems() itself.
  980. Notice that the control may only be sorted on client data associated with
  981. the items, so you must use SetItemData if you want to be able to sort the
  982. items in the control.
  983. Please see the @ref page_samples_listctrl for an example of using this function.
  984. @beginWxPerlOnly
  985. In wxPerl the comparison function must take just two parameters;
  986. however, you may use a closure to achieve an effect similar to the
  987. SortItems third parameter.
  988. @endWxPerlOnly
  989. */
  990. bool SortItems(wxListCtrlCompare fnSortCallBack, wxIntPtr data);
  991. protected:
  992. /**
  993. This function may be overridden in the derived class for a control with
  994. @c wxLC_VIRTUAL style. It should return the attribute for the specified
  995. @c item or @NULL to use the default appearance parameters.
  996. wxListCtrl will not delete the pointer or keep a reference of it.
  997. You can return the same wxListItemAttr pointer for every OnGetItemAttr() call.
  998. The base class version always returns @NULL.
  999. @see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(),
  1000. OnGetItemColumnAttr()
  1001. */
  1002. virtual wxListItemAttr* OnGetItemAttr(long item) const;
  1003. /**
  1004. This function may be overridden in the derived class for a control with
  1005. @c wxLC_VIRTUAL style.
  1006. It should return the attribute for the for the specified @a item and @a
  1007. column or @NULL to use the default appearance parameters.
  1008. The base class version returns @c OnGetItemAttr(item).
  1009. @note Currently this function is only called under wxMSW, the other
  1010. ports only support OnGetItemAttr()
  1011. @see OnGetItemAttr(), OnGetItemText(),
  1012. OnGetItemImage(), OnGetItemColumnImage(),
  1013. */
  1014. virtual wxListItemAttr* OnGetItemColumnAttr(long item, long column) const;
  1015. /**
  1016. Override this function in the derived class for a control with
  1017. @c wxLC_VIRTUAL and @c wxLC_REPORT styles in order to specify the image
  1018. index for the given line and column.
  1019. The base class version always calls OnGetItemImage() for the first column, else
  1020. it returns -1.
  1021. @see OnGetItemText(), OnGetItemImage(), OnGetItemAttr(),
  1022. OnGetItemColumnAttr()
  1023. */
  1024. virtual int OnGetItemColumnImage(long item, long column) const;
  1025. /**
  1026. This function must be overridden in the derived class for a control with
  1027. @c wxLC_VIRTUAL style having an "image list" (see SetImageList(); if the
  1028. control doesn't have an image list, it is not necessary to override it).
  1029. It should return the index of the items image in the controls image list
  1030. or -1 for no image.
  1031. In a control with @c wxLC_REPORT style, OnGetItemImage() only gets called for
  1032. the first column of each line.
  1033. The base class version always returns -1.
  1034. @see OnGetItemText(), OnGetItemColumnImage(), OnGetItemAttr()
  1035. */
  1036. virtual int OnGetItemImage(long item) const;
  1037. /**
  1038. This function @b must be overridden in the derived class for a control with
  1039. @c wxLC_VIRTUAL style. It should return the string containing the text of
  1040. the given @a column for the specified @c item.
  1041. @see SetItemCount(), OnGetItemImage(), OnGetItemColumnImage(), OnGetItemAttr()
  1042. */
  1043. virtual wxString OnGetItemText(long item, long column) const;
  1044. };
  1045. /**
  1046. @class wxListEvent
  1047. A list event holds information about events associated with wxListCtrl objects.
  1048. @beginEventTable{wxListEvent}
  1049. @event{EVT_LIST_BEGIN_DRAG(id, func)}
  1050. Begin dragging with the left mouse button.
  1051. @event{EVT_LIST_BEGIN_RDRAG(id, func)}
  1052. Begin dragging with the right mouse button.
  1053. @event{EVT_LIST_BEGIN_LABEL_EDIT(id, func)}
  1054. Begin editing a label. This can be prevented by calling Veto().
  1055. @event{EVT_LIST_END_LABEL_EDIT(id, func)}
  1056. Finish editing a label. This can be prevented by calling Veto().
  1057. @event{EVT_LIST_DELETE_ITEM(id, func)}
  1058. Delete an item.
  1059. @event{EVT_LIST_DELETE_ALL_ITEMS(id, func)}
  1060. Delete all items.
  1061. @event{EVT_LIST_ITEM_SELECTED(id, func)}
  1062. The item has been selected.
  1063. @event{EVT_LIST_ITEM_DESELECTED(id, func)}
  1064. The item has been deselected.
  1065. @event{EVT_LIST_ITEM_ACTIVATED(id, func)}
  1066. The item has been activated (ENTER or double click).
  1067. @event{EVT_LIST_ITEM_FOCUSED(id, func)}
  1068. The currently focused item has changed.
  1069. @event{EVT_LIST_ITEM_MIDDLE_CLICK(id, func)}
  1070. The middle mouse button has been clicked on an item.
  1071. @event{EVT_LIST_ITEM_RIGHT_CLICK(id, func)}
  1072. The right mouse button has been clicked on an item.
  1073. @event{EVT_LIST_KEY_DOWN(id, func)}
  1074. A key has been pressed. GetIndex() may be -1 if no item is selected.
  1075. @event{EVT_LIST_INSERT_ITEM(id, func)}
  1076. An item has been inserted.
  1077. @event{EVT_LIST_COL_CLICK(id, func)}
  1078. A column (m_col) has been left-clicked.
  1079. @event{EVT_LIST_COL_RIGHT_CLICK(id, func)}
  1080. A column (m_col) (which can be -1 if the click occurred outside any column)
  1081. has been right-clicked.
  1082. @event{EVT_LIST_COL_BEGIN_DRAG(id, func)}
  1083. The user started resizing a column - can be vetoed.
  1084. @event{EVT_LIST_COL_DRAGGING(id, func)}
  1085. The divider between columns is being dragged.
  1086. @event{EVT_LIST_COL_END_DRAG(id, func)}
  1087. A column has been resized by the user.
  1088. @event{EVT_LIST_CACHE_HINT(id, func)}
  1089. Prepare cache for a virtual list control
  1090. @endEventTable
  1091. @library{wxcore}
  1092. @category{events}
  1093. @see wxListCtrl
  1094. */
  1095. class wxListEvent : public wxNotifyEvent
  1096. {
  1097. public:
  1098. /**
  1099. Constructor.
  1100. */
  1101. wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
  1102. /**
  1103. For @c EVT_LIST_CACHE_HINT event only: return the first item which the
  1104. list control advises us to cache.
  1105. */
  1106. long GetCacheFrom() const;
  1107. /**
  1108. For @c EVT_LIST_CACHE_HINT event only: return the last item (inclusive)
  1109. which the list control advises us to cache.
  1110. */
  1111. long GetCacheTo() const;
  1112. /**
  1113. The column position: it is only used with @c COL events.
  1114. For the column dragging events, it is the column to the left of the divider
  1115. being dragged, for the column click events it may be -1 if the user clicked
  1116. in the list control header outside any column.
  1117. */
  1118. int GetColumn() const;
  1119. /**
  1120. The data.
  1121. */
  1122. wxUIntPtr GetData() const;
  1123. /**
  1124. The image.
  1125. */
  1126. int GetImage() const;
  1127. /**
  1128. The item index.
  1129. */
  1130. long GetIndex() const;
  1131. /**
  1132. An item object, used by some events. See also wxListCtrl::SetItem.
  1133. */
  1134. const wxListItem& GetItem() const;
  1135. /**
  1136. Key code if the event is a keypress event.
  1137. */
  1138. int GetKeyCode() const;
  1139. /**
  1140. The (new) item label for @c EVT_LIST_END_LABEL_EDIT event.
  1141. */
  1142. const wxString& GetLabel() const;
  1143. /**
  1144. The mask.
  1145. */
  1146. long GetMask() const;
  1147. /**
  1148. The position of the mouse pointer if the event is a drag event.
  1149. */
  1150. wxPoint GetPoint() const;
  1151. /**
  1152. The text.
  1153. */
  1154. const wxString& GetText() const;
  1155. /**
  1156. This method only makes sense for @c EVT_LIST_END_LABEL_EDIT message and
  1157. returns @true if it the label editing has been cancelled by the user
  1158. (GetLabel() returns an empty string in this case but it doesn't allow the
  1159. application to distinguish between really cancelling the edit and the
  1160. admittedly rare case when the user wants to rename it to an empty string).
  1161. */
  1162. bool IsEditCancelled() const;
  1163. };
  1164. wxEventType wxEVT_LIST_BEGIN_DRAG;
  1165. wxEventType wxEVT_LIST_BEGIN_RDRAG;
  1166. wxEventType wxEVT_LIST_BEGIN_LABEL_EDIT;
  1167. wxEventType wxEVT_LIST_END_LABEL_EDIT;
  1168. wxEventType wxEVT_LIST_DELETE_ITEM;
  1169. wxEventType wxEVT_LIST_DELETE_ALL_ITEMS;
  1170. wxEventType wxEVT_LIST_ITEM_SELECTED;
  1171. wxEventType wxEVT_LIST_ITEM_DESELECTED;
  1172. wxEventType wxEVT_LIST_KEY_DOWN;
  1173. wxEventType wxEVT_LIST_INSERT_ITEM;
  1174. wxEventType wxEVT_LIST_COL_CLICK;
  1175. wxEventType wxEVT_LIST_ITEM_RIGHT_CLICK;
  1176. wxEventType wxEVT_LIST_ITEM_MIDDLE_CLICK;
  1177. wxEventType wxEVT_LIST_ITEM_ACTIVATED;
  1178. wxEventType wxEVT_LIST_CACHE_HINT;
  1179. wxEventType wxEVT_LIST_COL_RIGHT_CLICK;
  1180. wxEventType wxEVT_LIST_COL_BEGIN_DRAG;
  1181. wxEventType wxEVT_LIST_COL_DRAGGING;
  1182. wxEventType wxEVT_LIST_COL_END_DRAG;
  1183. wxEventType wxEVT_LIST_ITEM_FOCUSED;
  1184. /**
  1185. @class wxListItemAttr
  1186. Represents the attributes (color, font, ...) of a wxListCtrl's wxListItem.
  1187. @library{wxcore}
  1188. @category{data}
  1189. @see @ref overview_listctrl, wxListCtrl, wxListItem
  1190. */
  1191. class wxListItemAttr
  1192. {
  1193. public:
  1194. /**
  1195. Default Constructor.
  1196. */
  1197. wxListItemAttr();
  1198. /**
  1199. Construct a wxListItemAttr with the specified foreground and
  1200. background colors and font.
  1201. */
  1202. wxListItemAttr(const wxColour& colText,
  1203. const wxColour& colBack,
  1204. const wxFont& font);
  1205. /**
  1206. Returns the currently set background color.
  1207. */
  1208. const wxColour& GetBackgroundColour() const;
  1209. /**
  1210. Returns the currently set font.
  1211. */
  1212. const wxFont& GetFont() const;
  1213. /**
  1214. Returns the currently set text color.
  1215. */
  1216. const wxColour& GetTextColour() const;
  1217. /**
  1218. Returns @true if the currently set background color is valid.
  1219. */
  1220. bool HasBackgroundColour() const;
  1221. /**
  1222. Returns @true if the currently set font is valid.
  1223. */
  1224. bool HasFont() const;
  1225. /**
  1226. Returns @true if the currently set text color is valid.
  1227. */
  1228. bool HasTextColour() const;
  1229. /**
  1230. Sets a new background color.
  1231. */
  1232. void SetBackgroundColour(const wxColour& colour);
  1233. /**
  1234. Sets a new font.
  1235. */
  1236. void SetFont(const wxFont& font);
  1237. /**
  1238. Sets a new text color.
  1239. */
  1240. void SetTextColour(const wxColour& colour);
  1241. };
  1242. /**
  1243. @class wxListView
  1244. This class currently simply presents a simpler to use interface for the
  1245. wxListCtrl -- it can be thought of as a @e façade for that complicated class.
  1246. Using it is preferable to using wxListCtrl directly whenever possible because
  1247. in the future some ports might implement wxListView but not the full set of
  1248. wxListCtrl features.
  1249. Other than different interface, this class is identical to wxListCtrl.
  1250. In particular, it uses the same events, same window styles and so on.
  1251. @library{wxcore}
  1252. @category{ctrl}
  1253. @appearance{listctrl}
  1254. @see wxListView::SetColumnImage
  1255. */
  1256. class wxListView : public wxListCtrl
  1257. {
  1258. public:
  1259. /**
  1260. Default constructor.
  1261. */
  1262. wxListView();
  1263. /**
  1264. Constructor, creating and showing a listview control.
  1265. @param parent
  1266. Parent window. Must not be @NULL.
  1267. @param id
  1268. Window identifier. The value wxID_ANY indicates a default value.
  1269. @param pos
  1270. Window position.
  1271. If ::wxDefaultPosition is specified then a default position is chosen.
  1272. @param size
  1273. Window size.
  1274. If ::wxDefaultSize is specified then the window is sized appropriately.
  1275. @param style
  1276. Window style. See wxListCtrl.
  1277. @param validator
  1278. Window validator.
  1279. @param name
  1280. Window name.
  1281. @see Create(), wxValidator
  1282. */
  1283. wxListView(wxWindow* parent, wxWindowID id,
  1284. const wxPoint& pos = wxDefaultPosition,
  1285. const wxSize& size = wxDefaultSize,
  1286. long style = wxLC_ICON,
  1287. const wxValidator& validator = wxDefaultValidator,
  1288. const wxString& name = wxListCtrlNameStr);
  1289. /**
  1290. Destructor, destroying the listview control.
  1291. */
  1292. virtual ~wxListView();
  1293. /**
  1294. Resets the column image -- after calling this function, no image will be shown.
  1295. @param col
  1296. the column to clear image for
  1297. @see SetColumnImage()
  1298. */
  1299. void ClearColumnImage(int col);
  1300. /**
  1301. Sets focus to the item with the given @a index.
  1302. */
  1303. void Focus(long index);
  1304. /**
  1305. Returns the first selected item in a (presumably) multiple selection control.
  1306. Together with GetNextSelected() it can be used to iterate over all selected
  1307. items in the control.
  1308. @return The first selected item, if any, -1 otherwise.
  1309. */
  1310. long GetFirstSelected() const;
  1311. /**
  1312. Returns the currently focused item or -1 if none.
  1313. @see IsSelected(), Focus()
  1314. */
  1315. long GetFocusedItem() const;
  1316. /**
  1317. Used together with GetFirstSelected() to iterate over all selected items
  1318. in the control.
  1319. @return Returns the next selected item or -1 if there are no more of them.
  1320. */
  1321. long GetNextSelected(long item) const;
  1322. /**
  1323. Returns @true if the item with the given @a index is selected,
  1324. @false otherwise.
  1325. @see GetFirstSelected(), GetNextSelected()
  1326. */
  1327. bool IsSelected(long index) const;
  1328. /**
  1329. Selects or unselects the given item.
  1330. @param n
  1331. the item to select or unselect
  1332. @param on
  1333. if @true (default), selects the item, otherwise unselects it
  1334. @see wxListCtrl::SetItemState
  1335. */
  1336. void Select(long n, bool on = true);
  1337. /**
  1338. Sets the column image for the specified column.
  1339. To use the column images, the control must have a valid image list with
  1340. at least one image.
  1341. @param col
  1342. the column to set image for
  1343. @param image
  1344. the index of the column image in the controls image list
  1345. */
  1346. void SetColumnImage(int col, int image);
  1347. };
  1348. /**
  1349. @class wxListItem
  1350. This class stores information about a wxListCtrl item or column.
  1351. wxListItem is a class which contains information about:
  1352. - Zero based item position; see SetId() and GetId().
  1353. - Zero based column index; see SetColumn() and GetColumn().
  1354. - The label (or header for columns); see SetText() and GetText().
  1355. - The zero based index into an image list; see GetImage() and SetImage().
  1356. - Application defined data; see SetData() and GetData().
  1357. - For columns only: the width of the column; see SetWidth() and GetWidth().
  1358. - For columns only: the format of the column; one of @c wxLIST_FORMAT_LEFT,
  1359. @c wxLIST_FORMAT_RIGHT, @c wxLIST_FORMAT_CENTRE. See SetAlign() and GetAlign().
  1360. - The state of the item; see SetState() and GetState().
  1361. This is a bitlist of the following flags:
  1362. - @c wxLIST_STATE_FOCUSED: The item has the focus.
  1363. - @c wxLIST_STATE_SELECTED: The item is selected.
  1364. - @c wxLIST_STATE_DONTCARE: Don't care what the state is. Win32 only.
  1365. - @c wxLIST_STATE_DROPHILITED: The item is highlighted to receive a drop event. Win32 only.
  1366. - @c wxLIST_STATE_CUT: The item is in the cut state. Win32 only.
  1367. - A mask indicating which state flags are valid; this is a bitlist of the
  1368. flags reported above for the item state. See SetStateMask() and GetStateMask().
  1369. - A mask indicating which fields of this class are valid; see SetMask() and GetMask().
  1370. This is a bitlist of the following flags:
  1371. - @c wxLIST_MASK_STATE: The state field is valid.
  1372. - @c wxLIST_MASK_TEXT: The label field is valid.
  1373. - @c wxLIST_MASK_IMAGE: The image field is valid.
  1374. - @c wxLIST_MASK_DATA: The application-defined data field is valid.
  1375. - @c wxLIST_MASK_WIDTH: The column width field is valid.
  1376. - @c wxLIST_MASK_FORMAT: The column format field is valid.
  1377. The wxListItem object can also contain item-specific colour and font
  1378. information: for this you need to call one of SetTextColour(), SetBackgroundColour()
  1379. or SetFont() functions on it passing it the colour/font to use.
  1380. If the colour/font is not specified, the default list control colour/font is used.
  1381. @library{wxcore}
  1382. @category{data}
  1383. @see wxListCtrl
  1384. */
  1385. class wxListItem : public wxObject
  1386. {
  1387. public:
  1388. /**
  1389. Constructor.
  1390. */
  1391. wxListItem();
  1392. /**
  1393. Resets the item state to the default.
  1394. */
  1395. void Clear();
  1396. /**
  1397. Returns the alignment for this item.
  1398. Can be one of @c wxLIST_FORMAT_LEFT, @c wxLIST_FORMAT_RIGHT or @c wxLIST_FORMAT_CENTRE.
  1399. */
  1400. wxListColumnFormat GetAlign() const;
  1401. /**
  1402. Returns the background colour for this item.
  1403. */
  1404. wxColour GetBackgroundColour() const;
  1405. /**
  1406. Returns the zero-based column; meaningful only in report mode.
  1407. */
  1408. int GetColumn() const;
  1409. /**
  1410. Returns client data associated with the control.
  1411. Please note that client data is associated with the item and not with subitems.
  1412. */
  1413. wxUIntPtr GetData() const;
  1414. /**
  1415. Returns the font used to display the item.
  1416. */
  1417. wxFont GetFont() const;
  1418. /**
  1419. Returns the zero-based item position.
  1420. */
  1421. long GetId() const;
  1422. /**
  1423. Returns the zero-based index of the image associated with the item into
  1424. the image list.
  1425. */
  1426. int GetImage() const;
  1427. /**
  1428. Returns a bit mask indicating which fields of the structure are valid.
  1429. Can be any combination of the following values:
  1430. - wxLIST_MASK_STATE: @b GetState is valid.
  1431. - wxLIST_MASK_TEXT: @b GetText is valid.
  1432. - wxLIST_MASK_IMAGE: @b GetImage is valid.
  1433. - wxLIST_MASK_DATA: @b GetData is valid.
  1434. - wxLIST_MASK_WIDTH: @b GetWidth is valid.
  1435. - wxLIST_MASK_FORMAT: @b GetFormat is valid.
  1436. */
  1437. long GetMask() const;
  1438. /**
  1439. Returns a bit field representing the state of the item.
  1440. Can be any combination of:
  1441. - wxLIST_STATE_DONTCARE: Don't care what the state is. Win32 only.
  1442. - wxLIST_STATE_DROPHILITED: The item is highlighted to receive a drop event. Win32 only.
  1443. - wxLIST_STATE_FOCUSED: The item has the focus.
  1444. - wxLIST_STATE_SELECTED: The item is selected.
  1445. - wxLIST_STATE_CUT: The item is in the cut state. Win32 only.
  1446. */
  1447. long GetState() const;
  1448. /**
  1449. Returns the label/header text.
  1450. */
  1451. const wxString& GetText() const;
  1452. /**
  1453. Returns the text colour.
  1454. */
  1455. wxColour GetTextColour() const;
  1456. /**
  1457. Meaningful only for column headers in report mode. Returns the column width.
  1458. */
  1459. int GetWidth() const;
  1460. /**
  1461. Sets the alignment for the item. See also GetAlign()
  1462. */
  1463. void SetAlign(wxListColumnFormat align);
  1464. /**
  1465. Sets the background colour for the item.
  1466. */
  1467. void SetBackgroundColour(const wxColour& colBack);
  1468. /**
  1469. Sets the zero-based column. Meaningful only in report mode.
  1470. */
  1471. void SetColumn(int col);
  1472. //@{
  1473. /**
  1474. Sets client data for the item.
  1475. Please note that client data is associated with the item and not with subitems.
  1476. */
  1477. void SetData(long data);
  1478. void SetData(void* data);
  1479. //@}
  1480. /**
  1481. Sets the font for the item.
  1482. */
  1483. void SetFont(const wxFont& font);
  1484. /**
  1485. Sets the zero-based item position.
  1486. */
  1487. void SetId(long id);
  1488. /**
  1489. Sets the zero-based index of the image associated with the item
  1490. into the image list.
  1491. */
  1492. void SetImage(int image);
  1493. /**
  1494. Sets the mask of valid fields. See GetMask().
  1495. */
  1496. void SetMask(long mask);
  1497. /**
  1498. Sets the item state flags (note that the valid state flags are influenced
  1499. by the value of the state mask, see wxListItem::SetStateMask).
  1500. See GetState() for valid flag values.
  1501. */
  1502. void SetState(long state);
  1503. /**
  1504. Sets the bitmask that is used to determine which of the state flags
  1505. are to be set. See also SetState().
  1506. */
  1507. void SetStateMask(long stateMask);
  1508. /**
  1509. Sets the text label for the item.
  1510. */
  1511. void SetText(const wxString& text);
  1512. /**
  1513. Sets the text colour for the item.
  1514. */
  1515. void SetTextColour(const wxColour& colText);
  1516. /**
  1517. Meaningful only for column headers in report mode. Sets the column width.
  1518. */
  1519. void SetWidth(int width);
  1520. };