]>
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 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
) 
  20 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
) 
  23 wxListCtrl::wxListCtrl() 
  25         m_imageListNormal 
= NULL
; 
  26         m_imageListSmall 
= NULL
; 
  27         m_imageListState 
= NULL
; 
  32 bool wxListCtrl::Create(wxWindow 
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, 
  33             long style
, const wxValidator
& validator
, const wxString
& name
) 
  35     m_imageListNormal 
= NULL
; 
  36     m_imageListSmall 
= NULL
; 
  37     m_imageListState 
= NULL
; 
  40     SetValidator(validator
); 
  43     m_windowStyle 
= style
; 
  47     m_windowId 
= (id 
== -1) ? NewControlId() : id
; 
  49     if (parent
) parent
->AddChild(this); 
  51     // TODO create list control 
  55 wxListCtrl::~wxListCtrl() 
  59 // Add or remove a single window style 
  60 void wxListCtrl::SetSingleStyle(long style
, bool add
) 
  62         long flag 
= GetWindowStyleFlag(); 
  64         // Get rid of conflicting styles 
  67                 if ( style 
& wxLC_MASK_TYPE
) 
  68                         flag 
= flag 
& ~wxLC_MASK_TYPE 
; 
  69                 if ( style 
& wxLC_MASK_ALIGN 
) 
  70                         flag 
= flag 
& ~wxLC_MASK_ALIGN 
; 
  71                 if ( style 
& wxLC_MASK_SORT 
) 
  72                         flag 
= flag 
& ~wxLC_MASK_SORT 
; 
  90         /* TODO RecreateWindow(); */ 
  93 // Set the whole window style 
  94 void wxListCtrl::SetWindowStyleFlag(long flag
) 
  98         /* TODO RecreateWindow(); */ 
 102 // Gets information about this column 
 103 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const 
 109 // Sets information about this column 
 110 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
) 
 116 // Gets the column width 
 117 int wxListCtrl::GetColumnWidth(int col
) const 
 123 // Sets the column width 
 124 bool wxListCtrl::SetColumnWidth(int col
, int width
) 
 130 // Gets the number of items that can fit vertically in the 
 131 // visible area of the list control (list or report view) 
 132 // or the total number of items in the list control (icon 
 133 // or small icon view) 
 134 int wxListCtrl::GetCountPerPage() const 
 140 // Gets the edit control for editing labels. 
 141 wxTextCtrl
* wxListCtrl::GetEditControl() const 
 146 // Gets information about the item 
 147 bool wxListCtrl::GetItem(wxListItem
& info
) const 
 153 // Sets information about the item 
 154 bool wxListCtrl::SetItem(wxListItem
& info
) 
 160 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
) 
 164         info
.m_mask 
= wxLIST_MASK_TEXT
; 
 165         info
.m_itemId 
= index
; 
 169                 info
.m_image 
= imageId
; 
 170                 info
.m_mask 
|= wxLIST_MASK_IMAGE
; 
 172         return SetItem(info
); 
 176 // Gets the item state 
 177 int wxListCtrl::GetItemState(long item
, long stateMask
) const 
 181         info
.m_mask 
= wxLIST_MASK_STATE 
; 
 182         info
.m_stateMask 
= stateMask
; 
 183         info
.m_itemId 
= item
; 
 191 // Sets the item state 
 192 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
) 
 196         info
.m_mask 
= wxLIST_MASK_STATE 
; 
 197         info
.m_state 
= state
; 
 198         info
.m_stateMask 
= stateMask
; 
 199         info
.m_itemId 
= item
; 
 201         return SetItem(info
); 
 204 // Sets the item image 
 205 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
) 
 209         info
.m_mask 
= wxLIST_MASK_IMAGE 
; 
 210         info
.m_image 
= image
; 
 211         info
.m_itemId 
= item
; 
 213         return SetItem(info
); 
 216 // Gets the item text 
 217 wxString 
wxListCtrl::GetItemText(long item
) const 
 221         info
.m_mask 
= wxLIST_MASK_TEXT 
; 
 222         info
.m_itemId 
= item
; 
 229 // Sets the item text 
 230 void wxListCtrl::SetItemText(long item
, const wxString
& str
) 
 234         info
.m_mask 
= wxLIST_MASK_TEXT 
; 
 235         info
.m_itemId 
= item
; 
 241 // Gets the item data 
 242 long wxListCtrl::GetItemData(long item
) const 
 246         info
.m_mask 
= wxLIST_MASK_DATA 
; 
 247         info
.m_itemId 
= item
; 
 254 // Sets the item data 
 255 bool wxListCtrl::SetItemData(long item
, long data
) 
 259         info
.m_mask 
= wxLIST_MASK_DATA 
; 
 260         info
.m_itemId 
= item
; 
 263         return SetItem(info
); 
 266 // Gets the item rectangle 
 267 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const 
 273 // Gets the item position 
 274 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const 
 280 // Sets the item position. 
 281 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
) 
 287 // Gets the number of items in the list control 
 288 int wxListCtrl::GetItemCount() const 
 294 // Retrieves the spacing between icons in pixels. 
 295 // If small is TRUE, gets the spacing for the small icon 
 296 // view, otherwise the large icon view. 
 297 int wxListCtrl::GetItemSpacing(bool isSmall
) const 
 303 // Gets the number of selected items in the list control 
 304 int wxListCtrl::GetSelectedItemCount() const 
 310 // Gets the text colour of the listview 
 311 wxColour 
wxListCtrl::GetTextColour() const 
 317 // Sets the text colour of the listview 
 318 void wxListCtrl::SetTextColour(const wxColour
& col
) 
 323 // Gets the index of the topmost visible item when in 
 324 // list or report view 
 325 long wxListCtrl::GetTopItem() const 
 331 // Searches for an item, starting from 'item'. 
 332 // 'geometry' is one of 
 333 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. 
 334 // 'state' is a state bit flag, one or more of 
 335 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. 
 336 // item can be -1 to find the first item that matches the 
 338 // Returns the item or -1 if unsuccessful. 
 339 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const 
 345 wxImageList 
*wxListCtrl::GetImageList(int which
) const 
 347         if ( which 
== wxIMAGE_LIST_NORMAL 
) 
 349                 return m_imageListNormal
; 
 351         else if ( which 
== wxIMAGE_LIST_SMALL 
) 
 353                 return m_imageListSmall
; 
 355         else if ( which 
== wxIMAGE_LIST_STATE 
) 
 357                 return m_imageListState
; 
 362 void wxListCtrl::SetImageList(wxImageList 
*imageList
, int which
) 
 365         if ( which 
== wxIMAGE_LIST_NORMAL 
) 
 367                 m_imageListNormal 
= imageList
; 
 369         else if ( which 
== wxIMAGE_LIST_SMALL 
) 
 371                 m_imageListSmall 
= imageList
; 
 373         else if ( which 
== wxIMAGE_LIST_STATE 
) 
 375                 m_imageListState 
= imageList
; 
 377         // TODO set image list 
 381 //////////////////////////////////////////////////////////////////////////// 
 383 // Arranges the items 
 384 bool wxListCtrl::Arrange(int flag
) 
 391 bool wxListCtrl::DeleteItem(long item
) 
 398 bool wxListCtrl::DeleteAllItems() 
 405 bool wxListCtrl::DeleteAllColumns() 
 412 bool wxListCtrl::DeleteColumn(int col
) 
 418 // Clears items, and columns if there are any. 
 419 void wxListCtrl::ClearAll() 
 422     if ( m_colCount 
> 0 ) 
 427 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
) 
 433 // End label editing, optionally cancelling the edit 
 434 bool wxListCtrl::EndEditLabel(bool cancel
) 
 440 // Ensures this item is visible 
 441 bool wxListCtrl::EnsureVisible(long item
) 
 447 // Find an item whose label matches this string, starting from the item after 'start' 
 448 // or the beginning if 'start' is -1. 
 449 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
) 
 455 // Find an item whose data matches this data, starting from the item after 'start' 
 456 // or the beginning if 'start' is -1. 
 457 long wxListCtrl::FindItem(long start
, long data
) 
 463 // Find an item nearest this position in the specified direction, starting from 
 464 // the item after 'start' or the beginning if 'start' is -1. 
 465 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
) 
 471 // Determines which item (if any) is at the specified point, 
 472 // giving details in 'flags' (see wxLIST_HITTEST_... flags above) 
 473 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
) 
 479 // Inserts an item, returning the index of the new item if successful, 
 481 long wxListCtrl::InsertItem(wxListItem
& info
) 
 487 long wxListCtrl::InsertItem(long index
, const wxString
& label
) 
 491         info
.m_mask 
= wxLIST_MASK_TEXT
; 
 492         info
.m_itemId 
= index
; 
 493         return InsertItem(info
); 
 496 // Inserts an image item 
 497 long wxListCtrl::InsertItem(long index
, int imageIndex
) 
 500         info
.m_image 
= imageIndex
; 
 501         info
.m_mask 
= wxLIST_MASK_IMAGE
; 
 502         info
.m_itemId 
= index
; 
 503         return InsertItem(info
); 
 506 // Inserts an image/string item 
 507 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
) 
 510         info
.m_image 
= imageIndex
; 
 512         info
.m_mask 
= wxLIST_MASK_IMAGE 
| wxLIST_MASK_TEXT
; 
 513         info
.m_itemId 
= index
; 
 514         return InsertItem(info
); 
 517 // For list view mode (only), inserts a column. 
 518 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
) 
 524 long wxListCtrl::InsertColumn(long col
, const wxString
& heading
, int format
, 
 528         item
.m_mask 
= wxLIST_MASK_TEXT 
| wxLIST_MASK_FORMAT
; 
 529         item
.m_text 
= heading
; 
 532                 item
.m_mask 
|= wxLIST_MASK_WIDTH
; 
 533                 item
.m_width 
= width
; 
 535         item
.m_format 
= format
; 
 537         return InsertColumn(col
, item
); 
 540 // Scrolls the list control. If in icon, small icon or report view mode, 
 541 // x specifies the number of pixels to scroll. If in list view mode, x 
 542 // specifies the number of columns to scroll. 
 543 // If in icon, small icon or list view mode, y specifies the number of pixels 
 544 // to scroll. If in report view mode, y specifies the number of lines to scroll. 
 545 bool wxListCtrl::ScrollList(int dx
, int dy
) 
 553 // fn is a function which takes 3 long arguments: item1, item2, data. 
 554 // item1 is the long data associated with a first item (NOT the index). 
 555 // item2 is the long data associated with a second item (NOT the index). 
 556 // data is the same value as passed to SortItems. 
 557 // The return value is a negative number if the first item should precede the second 
 558 // item, a positive number of the second item should precede the first, 
 559 // or zero if the two items are equivalent. 
 561 // data is arbitrary data to be passed to the sort function. 
 562 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
) 
 568 // List item structure 
 569 wxListItem::wxListItem() 
 579         m_format 
= wxLIST_FORMAT_CENTRE
; 
 584 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
) 
 586 wxListEvent::wxListEvent(wxEventType commandType
, int id
): 
 587   wxCommandEvent(commandType
, id
)