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