]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/listctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListCtrl. See also Robert's generic wxListCtrl
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "listctrl.h"
16 #include "wx/stubs/textctrl.h"
17 #include "wx/stubs/listctrl.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
21 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
25 wxListCtrl::wxListCtrl()
27 m_imageListNormal
= NULL
;
28 m_imageListSmall
= NULL
;
29 m_imageListState
= NULL
;
34 bool wxListCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
35 long style
, const wxValidator
& validator
, const wxString
& name
)
37 m_imageListNormal
= NULL
;
38 m_imageListSmall
= NULL
;
39 m_imageListState
= NULL
;
42 SetValidator(validator
);
45 m_windowStyle
= style
;
49 m_windowId
= (id
== -1) ? NewControlId() : id
;
51 if (parent
) parent
->AddChild(this);
53 // TODO create list control
57 wxListCtrl::~wxListCtrl()
61 // Add or remove a single window style
62 void wxListCtrl::SetSingleStyle(long style
, bool add
)
64 long flag
= GetWindowStyleFlag();
66 // Get rid of conflicting styles
69 if ( style
& wxLC_MASK_TYPE
)
70 flag
= flag
& ~wxLC_MASK_TYPE
;
71 if ( style
& wxLC_MASK_ALIGN
)
72 flag
= flag
& ~wxLC_MASK_ALIGN
;
73 if ( style
& wxLC_MASK_SORT
)
74 flag
= flag
& ~wxLC_MASK_SORT
;
92 /* TODO RecreateWindow(); */
95 // Set the whole window style
96 void wxListCtrl::SetWindowStyleFlag(long flag
)
100 /* TODO RecreateWindow(); */
104 // Gets information about this column
105 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
111 // Sets information about this column
112 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
118 // Gets the column width
119 int wxListCtrl::GetColumnWidth(int col
) const
125 // Sets the column width
126 bool wxListCtrl::SetColumnWidth(int col
, int width
)
132 // Gets the number of items that can fit vertically in the
133 // visible area of the list control (list or report view)
134 // or the total number of items in the list control (icon
135 // or small icon view)
136 int wxListCtrl::GetCountPerPage() const
142 // Gets the edit control for editing labels.
143 wxTextCtrl
* wxListCtrl::GetEditControl() const
148 // Gets information about the item
149 bool wxListCtrl::GetItem(wxListItem
& info
) const
155 // Sets information about the item
156 bool wxListCtrl::SetItem(wxListItem
& info
)
162 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
166 info
.m_mask
= wxLIST_MASK_TEXT
;
167 info
.m_itemId
= index
;
171 info
.m_image
= imageId
;
172 info
.m_mask
|= wxLIST_MASK_IMAGE
;
174 return SetItem(info
);
178 // Gets the item state
179 int wxListCtrl::GetItemState(long item
, long stateMask
) const
183 info
.m_mask
= wxLIST_MASK_STATE
;
184 info
.m_stateMask
= stateMask
;
185 info
.m_itemId
= item
;
193 // Sets the item state
194 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
198 info
.m_mask
= wxLIST_MASK_STATE
;
199 info
.m_state
= state
;
200 info
.m_stateMask
= stateMask
;
201 info
.m_itemId
= item
;
203 return SetItem(info
);
206 // Sets the item image
207 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
211 info
.m_mask
= wxLIST_MASK_IMAGE
;
212 info
.m_image
= image
;
213 info
.m_itemId
= item
;
215 return SetItem(info
);
218 // Gets the item text
219 wxString
wxListCtrl::GetItemText(long item
) const
223 info
.m_mask
= wxLIST_MASK_TEXT
;
224 info
.m_itemId
= item
;
231 // Sets the item text
232 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
236 info
.m_mask
= wxLIST_MASK_TEXT
;
237 info
.m_itemId
= item
;
243 // Gets the item data
244 long wxListCtrl::GetItemData(long item
) const
248 info
.m_mask
= wxLIST_MASK_DATA
;
249 info
.m_itemId
= item
;
256 // Sets the item data
257 bool wxListCtrl::SetItemData(long item
, long data
)
261 info
.m_mask
= wxLIST_MASK_DATA
;
262 info
.m_itemId
= item
;
265 return SetItem(info
);
268 // Gets the item rectangle
269 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
275 // Gets the item position
276 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
282 // Sets the item position.
283 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
289 // Gets the number of items in the list control
290 int wxListCtrl::GetItemCount() const
296 // Retrieves the spacing between icons in pixels.
297 // If small is TRUE, gets the spacing for the small icon
298 // view, otherwise the large icon view.
299 int wxListCtrl::GetItemSpacing(bool isSmall
) const
305 // Gets the number of selected items in the list control
306 int wxListCtrl::GetSelectedItemCount() const
312 // Gets the text colour of the listview
313 wxColour
wxListCtrl::GetTextColour() const
319 // Sets the text colour of the listview
320 void wxListCtrl::SetTextColour(const wxColour
& col
)
325 // Gets the index of the topmost visible item when in
326 // list or report view
327 long wxListCtrl::GetTopItem() const
333 // Searches for an item, starting from 'item'.
334 // 'geometry' is one of
335 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
336 // 'state' is a state bit flag, one or more of
337 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
338 // item can be -1 to find the first item that matches the
340 // Returns the item or -1 if unsuccessful.
341 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
347 wxImageList
*wxListCtrl::GetImageList(int which
) const
349 if ( which
== wxIMAGE_LIST_NORMAL
)
351 return m_imageListNormal
;
353 else if ( which
== wxIMAGE_LIST_SMALL
)
355 return m_imageListSmall
;
357 else if ( which
== wxIMAGE_LIST_STATE
)
359 return m_imageListState
;
364 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
367 if ( which
== wxIMAGE_LIST_NORMAL
)
369 m_imageListNormal
= imageList
;
371 else if ( which
== wxIMAGE_LIST_SMALL
)
373 m_imageListSmall
= imageList
;
375 else if ( which
== wxIMAGE_LIST_STATE
)
377 m_imageListState
= imageList
;
379 // TODO set image list
383 ////////////////////////////////////////////////////////////////////////////
385 // Arranges the items
386 bool wxListCtrl::Arrange(int flag
)
393 bool wxListCtrl::DeleteItem(long item
)
400 bool wxListCtrl::DeleteAllItems()
407 bool wxListCtrl::DeleteAllColumns()
414 bool wxListCtrl::DeleteColumn(int col
)
420 // Clears items, and columns if there are any.
421 void wxListCtrl::ClearAll()
424 if ( m_colCount
> 0 )
429 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
435 // End label editing, optionally cancelling the edit
436 bool wxListCtrl::EndEditLabel(bool cancel
)
442 // Ensures this item is visible
443 bool wxListCtrl::EnsureVisible(long item
)
449 // Find an item whose label matches this string, starting from the item after 'start'
450 // or the beginning if 'start' is -1.
451 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
457 // Find an item whose data matches this data, starting from the item after 'start'
458 // or the beginning if 'start' is -1.
459 long wxListCtrl::FindItem(long start
, long data
)
465 // Find an item nearest this position in the specified direction, starting from
466 // the item after 'start' or the beginning if 'start' is -1.
467 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
473 // Determines which item (if any) is at the specified point,
474 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
475 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
481 // Inserts an item, returning the index of the new item if successful,
483 long wxListCtrl::InsertItem(wxListItem
& info
)
489 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
493 info
.m_mask
= wxLIST_MASK_TEXT
;
494 info
.m_itemId
= index
;
495 return InsertItem(info
);
498 // Inserts an image item
499 long wxListCtrl::InsertItem(long index
, int imageIndex
)
502 info
.m_image
= imageIndex
;
503 info
.m_mask
= wxLIST_MASK_IMAGE
;
504 info
.m_itemId
= index
;
505 return InsertItem(info
);
508 // Inserts an image/string item
509 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
512 info
.m_image
= imageIndex
;
514 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
515 info
.m_itemId
= index
;
516 return InsertItem(info
);
519 // For list view mode (only), inserts a column.
520 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
526 long wxListCtrl::InsertColumn(long col
, const wxString
& heading
, int format
,
530 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
531 item
.m_text
= heading
;
534 item
.m_mask
|= wxLIST_MASK_WIDTH
;
535 item
.m_width
= width
;
537 item
.m_format
= format
;
539 return InsertColumn(col
, item
);
542 // Scrolls the list control. If in icon, small icon or report view mode,
543 // x specifies the number of pixels to scroll. If in list view mode, x
544 // specifies the number of columns to scroll.
545 // If in icon, small icon or list view mode, y specifies the number of pixels
546 // to scroll. If in report view mode, y specifies the number of lines to scroll.
547 bool wxListCtrl::ScrollList(int dx
, int dy
)
555 // fn is a function which takes 3 long arguments: item1, item2, data.
556 // item1 is the long data associated with a first item (NOT the index).
557 // item2 is the long data associated with a second item (NOT the index).
558 // data is the same value as passed to SortItems.
559 // The return value is a negative number if the first item should precede the second
560 // item, a positive number of the second item should precede the first,
561 // or zero if the two items are equivalent.
563 // data is arbitrary data to be passed to the sort function.
564 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
570 // List item structure
571 wxListItem::wxListItem()
581 m_format
= wxLIST_FORMAT_CENTRE
;
586 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
588 wxListEvent::wxListEvent(wxEventType commandType
, int id
):
589 wxCommandEvent(commandType
, id
)