1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/listctrl.cpp
4 // Author: William Osborne
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "listctrl.h"
22 #pragma implementation "listctrlbase.h"
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
38 #include "wx/settings.h"
41 #include "wx/textctrl.h"
42 #include "wx/imaglist.h"
43 #include "wx/listctrl.h"
44 #include "wx/dcclient.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
59 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
60 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
61 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
67 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
68 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
69 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
70 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
71 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
73 #if wxUSE_EXTENDED_RTTI
74 WX_DEFINE_FLAGS( wxListCtrlStyle
)
76 wxBEGIN_FLAGS( wxListCtrlStyle
)
77 // new style border flags, we put them first to
78 // use them for streaming out
79 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
80 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
81 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
82 wxFLAGS_MEMBER(wxBORDER_RAISED
)
83 wxFLAGS_MEMBER(wxBORDER_STATIC
)
84 wxFLAGS_MEMBER(wxBORDER_NONE
)
86 // old style border flags
87 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
88 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
89 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
90 wxFLAGS_MEMBER(wxRAISED_BORDER
)
91 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
92 wxFLAGS_MEMBER(wxBORDER
)
94 // standard window styles
95 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
96 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
97 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
98 wxFLAGS_MEMBER(wxWANTS_CHARS
)
99 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
100 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
101 wxFLAGS_MEMBER(wxVSCROLL
)
102 wxFLAGS_MEMBER(wxHSCROLL
)
104 wxFLAGS_MEMBER(wxLC_LIST
)
105 wxFLAGS_MEMBER(wxLC_REPORT
)
106 wxFLAGS_MEMBER(wxLC_ICON
)
107 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
108 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
109 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
110 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
111 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
112 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
113 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
114 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
115 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
116 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
117 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
119 wxEND_FLAGS( wxListCtrlStyle
)
121 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
123 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
124 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
126 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
127 wxEND_PROPERTIES_TABLE()
129 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
130 wxEND_HANDLERS_TABLE()
132 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
135 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
138 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
141 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
142 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
144 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
146 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
147 EVT_PAINT(wxListCtrl::OnPaint
)
150 // ============================================================================
152 // ============================================================================
154 // ----------------------------------------------------------------------------
155 // wxListCtrl construction
156 // ----------------------------------------------------------------------------
158 void wxListCtrl::Init()
162 bool wxListCtrl::Create(wxWindow
*parent
,
167 const wxValidator
& validator
,
168 const wxString
& name
)
173 void wxListCtrl::UpdateStyle()
177 void wxListCtrl::FreeAllInternalData()
181 wxListCtrl::~wxListCtrl()
185 // ----------------------------------------------------------------------------
186 // set/get/change style
187 // ----------------------------------------------------------------------------
189 // Add or remove a single window style
190 void wxListCtrl::SetSingleStyle(long style
, bool add
)
194 // Set the whole window style
195 void wxListCtrl::SetWindowStyleFlag(long flag
)
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 /* static */ wxVisualAttributes
wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
205 wxVisualAttributes attrs
;
210 // Sets the foreground, i.e. text, colour
211 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
216 // Sets the background colour
217 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
222 // Gets information about this column
223 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
228 // Sets information about this column
229 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
234 // Gets the column width
235 int wxListCtrl::GetColumnWidth(int col
) const
240 // Sets the column width
241 bool wxListCtrl::SetColumnWidth(int col
, int width
)
246 // Gets the number of items that can fit vertically in the
247 // visible area of the list control (list or report view)
248 // or the total number of items in the list control (icon
249 // or small icon view)
250 int wxListCtrl::GetCountPerPage() const
255 // Gets the edit control for editing labels.
256 wxTextCtrl
* wxListCtrl::GetEditControl() const
261 // Gets information about the item
262 bool wxListCtrl::GetItem(wxListItem
& info
) const
267 // Sets information about the item
268 bool wxListCtrl::SetItem(wxListItem
& info
)
273 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
279 // Gets the item state
280 int wxListCtrl::GetItemState(long item
, long stateMask
) const
285 // Sets the item state
286 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
291 // Sets the item image
292 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
297 // Gets the item text
298 wxString
wxListCtrl::GetItemText(long item
) const
305 // Sets the item text
306 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
310 // Gets the item data
311 long wxListCtrl::GetItemData(long item
) const
316 // Sets the item data
317 bool wxListCtrl::SetItemData(long item
, long data
)
322 wxRect
wxListCtrl::GetViewRect() const
329 // Gets the item rectangle
330 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
335 // Gets the item position
336 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
341 // Sets the item position.
342 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
347 // Gets the number of items in the list control
348 int wxListCtrl::GetItemCount() const
353 wxSize
wxListCtrl::GetItemSpacing() const
358 int wxListCtrl::GetItemSpacing(bool isSmall
) const
363 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
367 wxColour
wxListCtrl::GetItemTextColour( long item
) const
374 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
378 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
385 // Gets the number of selected items in the list control
386 int wxListCtrl::GetSelectedItemCount() const
391 // Gets the text colour of the listview
392 wxColour
wxListCtrl::GetTextColour() const
398 // Sets the text colour of the listview
399 void wxListCtrl::SetTextColour(const wxColour
& col
)
403 // Gets the index of the topmost visible item when in
404 // list or report view
405 long wxListCtrl::GetTopItem() const
410 // Searches for an item, starting from 'item'.
411 // 'geometry' is one of
412 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
413 // 'state' is a state bit flag, one or more of
414 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
415 // item can be -1 to find the first item that matches the
417 // Returns the item or -1 if unsuccessful.
418 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
424 wxImageList
*wxListCtrl::GetImageList(int which
) const
429 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
433 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
437 // ----------------------------------------------------------------------------
439 // ----------------------------------------------------------------------------
441 // Arranges the items
442 bool wxListCtrl::Arrange(int flag
)
448 bool wxListCtrl::DeleteItem(long item
)
454 bool wxListCtrl::DeleteAllItems()
460 bool wxListCtrl::DeleteAllColumns()
466 bool wxListCtrl::DeleteColumn(int col
)
471 // Clears items, and columns if there are any.
472 void wxListCtrl::ClearAll()
476 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
481 // End label editing, optionally cancelling the edit
482 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
487 // Ensures this item is visible
488 bool wxListCtrl::EnsureVisible(long item
)
493 // Find an item whose label matches this string, starting from the item after 'start'
494 // or the beginning if 'start' is -1.
495 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
500 // Find an item whose data matches this data, starting from the item after 'start'
501 // or the beginning if 'start' is -1.
502 // NOTE : Lindsay Mathieson - 14-July-2002
503 // No longer use ListView_FindItem as the data attribute is now stored
504 // in a wxListItemInternalData structure refernced by the actual lParam
505 long wxListCtrl::FindItem(long start
, long data
)
510 // Find an item nearest this position in the specified direction, starting from
511 // the item after 'start' or the beginning if 'start' is -1.
512 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
517 // Determines which item (if any) is at the specified point,
518 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
519 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
524 // Inserts an item, returning the index of the new item if successful,
526 long wxListCtrl::InsertItem(wxListItem
& info
)
531 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
536 // Inserts an image item
537 long wxListCtrl::InsertItem(long index
, int imageIndex
)
542 // Inserts an image/string item
543 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
548 // For list view mode (only), inserts a column.
549 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
554 long wxListCtrl::InsertColumn(long col
,
555 const wxString
& heading
,
562 // scroll the control by the given number of pixels (exception: in list view,
563 // dx is interpreted as number of columns)
564 bool wxListCtrl::ScrollList(int dx
, int dy
)
571 // fn is a function which takes 3 long arguments: item1, item2, data.
572 // item1 is the long data associated with a first item (NOT the index).
573 // item2 is the long data associated with a second item (NOT the index).
574 // data is the same value as passed to SortItems.
575 // The return value is a negative number if the first item should precede the second
576 // item, a positive number of the second item should precede the first,
577 // or zero if the two items are equivalent.
579 // data is arbitrary data to be passed to the sort function.
581 // Internal structures for proxying the user compare function
582 // so that we can pass it the *real* user data
584 // translate lParam data and call user func
585 struct wxInternalDataSort
587 wxListCtrlCompare user_fn
;
591 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
593 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
595 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
596 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
598 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
599 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
601 return internalData
->user_fn(d1
, d2
, internalData
->data
);
605 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
612 // ----------------------------------------------------------------------------
613 // message processing
614 // ----------------------------------------------------------------------------
616 // Necessary for drawing hrules and vrules, if specified
617 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
621 // ----------------------------------------------------------------------------
622 // virtual list controls
623 // ----------------------------------------------------------------------------
625 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
627 return wxEmptyString
;
630 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
635 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
637 // no attributes by default
641 void wxListCtrl::SetItemCount(long count
)
645 void wxListCtrl::RefreshItem(long item
)
649 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
653 // ----------------------------------------------------------------------------
654 // internal data stuff
655 // ----------------------------------------------------------------------------
657 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
662 static wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
664 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
667 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
672 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
676 #endif // wxUSE_LISTCTRL