]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/os2/listctrl.h | |
3 | // Purpose: wxListCtrl class | |
4 | // Author: | |
5 | // Modified by: | |
6 | // Created: | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWidgets team | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_LISTCTRL_H_ | |
13 | #define _WX_LISTCTRL_H_ | |
14 | ||
15 | #if wxUSE_LISTCTRL | |
16 | ||
17 | #include "wx/control.h" | |
18 | #include "wx/event.h" | |
19 | #include "wx/hash.h" | |
20 | #include "wx/textctrl.h" | |
21 | ||
22 | ||
23 | class WXDLLIMPEXP_FWD_CORE wxImageList; | |
24 | ||
25 | typedef int (wxCALLBACK *wxListCtrlCompare)(long lItem1, long lItem2, long lSortData); | |
26 | ||
27 | class WXDLLEXPORT wxListCtrl: public wxControl | |
28 | { | |
29 | public: | |
30 | wxListCtrl() { Init(); } | |
31 | wxListCtrl( wxWindow* pParent | |
32 | ,wxWindowID vId = -1 | |
33 | ,const wxPoint& rPos = wxDefaultPosition | |
34 | ,const wxSize& rSize = wxDefaultSize | |
35 | ,long lStyle = wxLC_ICON | |
36 | ,const wxValidator& rValidator = wxDefaultValidator | |
37 | ,const wxString& rsName = wxListCtrlNameStr) | |
38 | { | |
39 | Init(); | |
40 | Create( pParent | |
41 | ,vId | |
42 | ,rPos | |
43 | ,rSize | |
44 | ,lStyle | |
45 | ,rValidator | |
46 | ,rsName | |
47 | ); | |
48 | } | |
49 | virtual ~wxListCtrl(); | |
50 | ||
51 | bool Create( wxWindow* pParent | |
52 | ,wxWindowID vId = -1 | |
53 | ,const wxPoint& rPos = wxDefaultPosition | |
54 | ,const wxSize& rSize = wxDefaultSize | |
55 | ,long lStyle = wxLC_ICON | |
56 | ,const wxValidator& rValidator = wxDefaultValidator | |
57 | ,const wxString& rsName = wxListCtrlNameStr | |
58 | ); | |
59 | ||
60 | ||
61 | // Attributes | |
62 | //////////////////////////////////////////////////////////////////////////// | |
63 | // | |
64 | ||
65 | // | |
66 | // Set the control colours | |
67 | // | |
68 | bool SetForegroundColour(const wxColour& rCol); | |
69 | bool SetBackgroundColour(const wxColour& rCol); | |
70 | ||
71 | // | |
72 | // Information about this column | |
73 | // | |
74 | bool GetColumn( int nCol | |
75 | ,wxListItem& rItem | |
76 | ) const; | |
77 | bool SetColumn( int nCol | |
78 | ,wxListItem& rItem | |
79 | ); | |
80 | ||
81 | // | |
82 | // Column width | |
83 | // | |
84 | int GetColumnWidth(int nCol) const; | |
85 | bool SetColumnWidth( int nCol | |
86 | ,int nWidth | |
87 | ); | |
88 | ||
89 | // | |
90 | // Gets the number of items that can fit vertically in the | |
91 | // visible area of the list control (list or report view) | |
92 | // or the total number of items in the list control (icon | |
93 | // or small icon view) | |
94 | // | |
95 | int GetCountPerPage(void) const; | |
96 | ||
97 | wxRect GetViewRect() const; | |
98 | // | |
99 | // Gets the edit control for editing labels. | |
100 | // | |
101 | wxTextCtrl* GetEditControl(void) const; | |
102 | ||
103 | // | |
104 | // Information about the item | |
105 | // | |
106 | bool GetItem(wxListItem& rInfo) const; | |
107 | bool SetItem(wxListItem& rInfo); | |
108 | ||
109 | // | |
110 | // Sets a string field at a particular column | |
111 | // | |
112 | long SetItem( long lIndex | |
113 | ,int nCol | |
114 | ,const wxString& rsLabel | |
115 | ,int nImageId = -1 | |
116 | ); | |
117 | ||
118 | // | |
119 | // Item state | |
120 | // | |
121 | int GetItemState( long lItem | |
122 | ,long lStateMask | |
123 | ) const; | |
124 | bool SetItemState( long lItem | |
125 | ,long lState | |
126 | ,long lStateMask | |
127 | ); | |
128 | ||
129 | // | |
130 | // Sets the item image | |
131 | // | |
132 | bool SetItemImage( long lItem | |
133 | ,int nImage | |
134 | ,int lSelImage | |
135 | ); | |
136 | bool SetItemColumnImage( long lItem | |
137 | ,long lColumn | |
138 | ,int nImage | |
139 | ); | |
140 | ||
141 | // | |
142 | // Item text | |
143 | // | |
144 | wxString GetItemText(long lItem) const; | |
145 | void SetItemText( long lItem | |
146 | ,const wxString& rsStr | |
147 | ); | |
148 | ||
149 | // | |
150 | // Item data | |
151 | // | |
152 | long GetItemData(long lItem) const; | |
153 | bool SetItemPtrData(long item, wxUIntPtr data); | |
154 | bool SetItemData(long item, long data) { return SetItemPtrData(item, data); } | |
155 | ||
156 | // | |
157 | // Gets the item rectangle | |
158 | // | |
159 | bool GetItemRect( long lItem | |
160 | ,wxRect& rRect | |
161 | ,int nCode = wxLIST_RECT_BOUNDS | |
162 | ) const; | |
163 | ||
164 | // | |
165 | // Item position | |
166 | // | |
167 | bool GetItemPosition( long lItem | |
168 | ,wxPoint& rPos | |
169 | ) const; | |
170 | bool SetItemPosition( long lItem | |
171 | ,const wxPoint& rPos | |
172 | ); | |
173 | ||
174 | // | |
175 | // Gets the number of items in the list control | |
176 | // | |
177 | int GetItemCount(void) const; | |
178 | ||
179 | // | |
180 | // Gets the number of columns in the list control | |
181 | // | |
182 | inline int GetColumnCount(void) const { return m_nColCount; } | |
183 | ||
184 | // | |
185 | // Retrieves the spacing between icons in pixels. | |
186 | // If bIsSmall is true, gets the spacing for the small icon | |
187 | // view, otherwise the large icon view. | |
188 | // | |
189 | int GetItemSpacing(bool bIsSmall) const; | |
190 | ||
191 | // | |
192 | // Foreground colour of an item. | |
193 | // | |
194 | wxColour GetItemTextColour(long lItem) const; | |
195 | void SetItemTextColour( long lItem | |
196 | ,const wxColour& rCol | |
197 | ); | |
198 | ||
199 | // | |
200 | // Background colour of an item. | |
201 | // | |
202 | wxColour GetItemBackgroundColour(long lItem ) const; | |
203 | void SetItemBackgroundColour( long lItem | |
204 | ,const wxColour& rCol | |
205 | ); | |
206 | ||
207 | // | |
208 | // Gets the number of selected items in the list control | |
209 | // | |
210 | int GetSelectedItemCount(void) const; | |
211 | ||
212 | // | |
213 | // Text colour of the listview | |
214 | // | |
215 | wxColour GetTextColour(void) const; | |
216 | void SetTextColour(const wxColour& rCol); | |
217 | ||
218 | // | |
219 | // Gets the index of the topmost visible item when in | |
220 | // list or report view | |
221 | // | |
222 | long GetTopItem(void) const; | |
223 | ||
224 | // | |
225 | // Add or remove a single window style | |
226 | void SetSingleStyle( long lStyle | |
227 | ,bool bAdd = true | |
228 | ); | |
229 | ||
230 | // | |
231 | // Set the whole window style | |
232 | // | |
233 | void SetWindowStyleFlag(long lStyle); | |
234 | ||
235 | // | |
236 | // Searches for an item, starting from 'item'. | |
237 | // item can be -1 to find the first item that matches the | |
238 | // specified flags. | |
239 | // Returns the item or -1 if unsuccessful. | |
240 | long GetNextItem( long lItem | |
241 | ,int nGeometry = wxLIST_NEXT_ALL | |
242 | ,int lState = wxLIST_STATE_DONTCARE | |
243 | ) const; | |
244 | ||
245 | // | |
246 | // Gets one of the three image lists | |
247 | // | |
248 | wxImageList* GetImageList(int nWhich) const; | |
249 | ||
250 | // | |
251 | // Sets the image list | |
252 | // | |
253 | void SetImageList( wxImageList* pImageList | |
254 | ,int nWhich | |
255 | ); | |
256 | void AssignImageList( wxImageList* pImageList | |
257 | ,int nWhich | |
258 | ); | |
259 | ||
260 | // | |
261 | // Returns true if it is a virtual list control | |
262 | // | |
263 | inline bool IsVirtual() const { return (GetWindowStyle() & wxLC_VIRTUAL) != 0; } | |
264 | ||
265 | // | |
266 | // Refresh items selectively (only useful for virtual list controls) | |
267 | // | |
268 | void RefreshItem(long lItem); | |
269 | void RefreshItems( long lItemFrom | |
270 | ,long lItemTo | |
271 | ); | |
272 | ||
273 | // | |
274 | // Operations | |
275 | //////////////////////////////////////////////////////////////////////////// | |
276 | // | |
277 | ||
278 | // | |
279 | // Arranges the items | |
280 | // | |
281 | bool Arrange(int nFlag = wxLIST_ALIGN_DEFAULT); | |
282 | ||
283 | // | |
284 | // Deletes an item | |
285 | // | |
286 | bool DeleteItem(long lItem); | |
287 | ||
288 | // | |
289 | // Deletes all items | |
290 | bool DeleteAllItems(void); | |
291 | ||
292 | // | |
293 | // Deletes a column | |
294 | // | |
295 | bool DeleteColumn(int nCol); | |
296 | ||
297 | // | |
298 | // Deletes all columns | |
299 | // | |
300 | bool DeleteAllColumns(void); | |
301 | ||
302 | // | |
303 | // Clears items, and columns if there are any. | |
304 | // | |
305 | void ClearAll(void); | |
306 | ||
307 | // | |
308 | // Edit the label | |
309 | // | |
310 | wxTextCtrl* EditLabel( long lItem | |
311 | ,wxClassInfo* pTextControlClass = CLASSINFO(wxTextCtrl) | |
312 | ); | |
313 | ||
314 | // | |
315 | // End label editing, optionally cancelling the edit | |
316 | // | |
317 | bool EndEditLabel(bool bCancel); | |
318 | ||
319 | // | |
320 | // Ensures this item is visible | |
321 | // | |
322 | bool EnsureVisible(long lItem); | |
323 | ||
324 | // | |
325 | // Find an item whose label matches this string, starting from the item after 'start' | |
326 | // or the beginning if 'start' is -1. | |
327 | // | |
328 | long FindItem( long lStart | |
329 | ,const wxString& rsStr | |
330 | ,bool bPartial = false | |
331 | ); | |
332 | ||
333 | // | |
334 | // Find an item whose data matches this data, starting from the item after 'start' | |
335 | // or the beginning if 'start' is -1. | |
336 | // | |
337 | long FindItem( long lStart | |
338 | ,long lData | |
339 | ); | |
340 | ||
341 | // | |
342 | // Find an item nearest this position in the specified direction, starting from | |
343 | // the item after 'start' or the beginning if 'start' is -1. | |
344 | // | |
345 | long FindItem( long lStart | |
346 | ,const wxPoint& rPoint | |
347 | ,int lDirection | |
348 | ); | |
349 | ||
350 | // | |
351 | // Determines which item (if any) is at the specified point, | |
352 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
353 | // | |
354 | long HitTest( const wxPoint& rPoint | |
355 | ,int& rFlags | |
356 | ); | |
357 | ||
358 | // | |
359 | // Inserts an item, returning the index of the new item if successful, | |
360 | // -1 otherwise. | |
361 | // | |
362 | long InsertItem(wxListItem& rInfo); | |
363 | ||
364 | // | |
365 | // Insert a string item | |
366 | // | |
367 | long InsertItem( long lIndex | |
368 | ,const wxString& rsLabel | |
369 | ); | |
370 | ||
371 | // | |
372 | // Insert an image item | |
373 | // | |
374 | long InsertItem( long lIndex | |
375 | ,int nImageIndex | |
376 | ); | |
377 | ||
378 | // | |
379 | // Insert an image/string item | |
380 | // | |
381 | long InsertItem( long lIndex | |
382 | ,const wxString& rsLabel | |
383 | ,int nImageIndex | |
384 | ); | |
385 | ||
386 | // | |
387 | // For list view mode (only), inserts a column. | |
388 | // | |
389 | long InsertColumn( long lCol | |
390 | ,wxListItem& rInfo | |
391 | ); | |
392 | ||
393 | long InsertColumn( long lCol | |
394 | ,const wxString& rsHeading | |
395 | ,int nFormat = wxLIST_FORMAT_LEFT | |
396 | ,int lWidth = -1 | |
397 | ); | |
398 | ||
399 | // | |
400 | // set the number of items in a virtual list control | |
401 | // | |
402 | void SetItemCount(long lCount); | |
403 | ||
404 | // | |
405 | // Scrolls the list control. If in icon, small icon or report view mode, | |
406 | // x specifies the number of pixels to scroll. If in list view mode, x | |
407 | // specifies the number of columns to scroll. | |
408 | // If in icon, small icon or list view mode, y specifies the number of pixels | |
409 | // to scroll. If in report view mode, y specifies the number of lines to scroll. | |
410 | // | |
411 | bool ScrollList( int nDx | |
412 | ,int nDy | |
413 | ); | |
414 | ||
415 | // Sort items. | |
416 | ||
417 | // | |
418 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
419 | // item1 is the long data associated with a first item (NOT the index). | |
420 | // item2 is the long data associated with a second item (NOT the index). | |
421 | // data is the same value as passed to SortItems. | |
422 | // The return value is a negative number if the first item should precede the second | |
423 | // item, a positive number of the second item should precede the first, | |
424 | // or zero if the two items are equivalent. | |
425 | // | |
426 | // data is arbitrary data to be passed to the sort function. | |
427 | // | |
428 | bool SortItems( wxListCtrlCompare fn | |
429 | ,long lData | |
430 | ); | |
431 | ||
432 | // | |
433 | // IMPLEMENTATION | |
434 | // -------------- | |
435 | // | |
436 | virtual bool OS2Command( WXUINT uParam | |
437 | ,WXWORD wId | |
438 | ); | |
439 | // | |
440 | // Bring the control in sync with current m_windowStyle value | |
441 | // | |
442 | void UpdateStyle(void); | |
443 | ||
444 | // | |
445 | // Implementation: converts wxWidgets style to MSW style. | |
446 | // Can be a single style flag or a bit list. | |
447 | // oldStyle is 'normalised' so that it doesn't contain | |
448 | // conflicting styles. | |
449 | // | |
450 | long ConvertToOS2Style( long& lOldStyle | |
451 | ,long lStyle | |
452 | ) const; | |
453 | long ConvertArrangeToOS2Style(long lStyle); | |
454 | long ConvertViewToOS2Style(long lStyle); | |
455 | ||
456 | virtual MRESULT OS2WindowProc( WXUINT uMsg | |
457 | ,WXWPARAM wParam | |
458 | ,WXLPARAM lParam | |
459 | ); | |
460 | ||
461 | // Event handlers | |
462 | //////////////////////////////////////////////////////////////////////////// | |
463 | // Necessary for drawing hrules and vrules, if specified | |
464 | void OnPaint(wxPaintEvent& rEvent); | |
465 | ||
466 | protected: | |
467 | // | |
468 | // common part of all ctors | |
469 | // | |
470 | void Init(void); | |
471 | ||
472 | // | |
473 | // Free memory taken by all internal data | |
474 | // | |
475 | void FreeAllInternalData(void); | |
476 | ||
477 | wxTextCtrl* m_pTextCtrl; // The control used for editing a label | |
478 | wxImageList* m_pImageListNormal; // The image list for normal icons | |
479 | wxImageList* m_pImageListSmall; // The image list for small icons | |
480 | wxImageList* m_pImageListState; // The image list state icons (not implemented yet) | |
481 | bool m_bOwnsImageListNormal; | |
482 | bool m_bOwnsImageListSmall; | |
483 | bool m_bOwnsImageListState; | |
484 | long m_lBaseStyle; // Basic PM style flags, for recreation purposes | |
485 | int m_nColCount; // PM doesn't have GetColumnCount so must | |
486 | // keep track of inserted/deleted columns | |
487 | ||
488 | // | |
489 | // true if we have any internal data (user data & attributes) | |
490 | // | |
491 | bool m_bAnyInternalData; | |
492 | ||
493 | // | |
494 | // true if we have any items with custom attributes | |
495 | // | |
496 | bool m_bHasAnyAttr; | |
497 | ||
498 | // | |
499 | // These functions are only used for virtual list view controls, i.e. the | |
500 | // ones with wxLC_VIRTUAL style | |
501 | // | |
502 | // return the text for the given column of the given item | |
503 | // | |
504 | virtual wxString OnGetItemText( long lItem | |
505 | ,long lColumn | |
506 | ) const; | |
507 | ||
508 | // | |
509 | // Return the icon for the given item. In report view, OnGetItemImage will | |
510 | // only be called for the first column. See OnGetItemColumnImage for | |
511 | // details. | |
512 | // | |
513 | virtual int OnGetItemImage(long lItem) const; | |
514 | ||
515 | // | |
516 | // Return the icon for the given item and column | |
517 | // | |
518 | virtual int OnGetItemColumnImage(long lItem, long lColumn) const; | |
519 | ||
520 | // | |
521 | // Return the attribute for the item (may return NULL if none) | |
522 | // | |
523 | virtual wxListItemAttr* OnGetItemAttr(long lItem) const; | |
524 | ||
525 | private: | |
526 | bool DoCreateControl( int nX | |
527 | ,int nY | |
528 | ,int nWidth | |
529 | ,int nHeight | |
530 | ); | |
531 | ||
532 | DECLARE_DYNAMIC_CLASS(wxListCtrl) | |
533 | DECLARE_EVENT_TABLE() | |
534 | DECLARE_NO_COPY_CLASS(wxListCtrl) | |
535 | }; // end of CLASS wxListCtrl | |
536 | ||
537 | #endif // wxUSE_LISTCTRL | |
538 | ||
539 | #endif // _WX_LISTCTRL_H_ | |
540 |