1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/listctrl.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
35 #include "wx/textctrl.h"
38 #include "wx/imaglist.h"
39 #include "wx/listctrl.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
47 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
59 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
60 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
61 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
68 #if wxUSE_EXTENDED_RTTI
69 WX_DEFINE_FLAGS( wxListCtrlStyle
)
71 wxBEGIN_FLAGS( wxListCtrlStyle
)
72 // new style border flags, we put them first to
73 // use them for streaming out
74 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
75 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
76 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
77 wxFLAGS_MEMBER(wxBORDER_RAISED
)
78 wxFLAGS_MEMBER(wxBORDER_STATIC
)
79 wxFLAGS_MEMBER(wxBORDER_NONE
)
81 // old style border flags
82 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
83 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
84 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
85 wxFLAGS_MEMBER(wxRAISED_BORDER
)
86 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
87 wxFLAGS_MEMBER(wxBORDER
)
89 // standard window styles
90 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
91 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
92 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
93 wxFLAGS_MEMBER(wxWANTS_CHARS
)
94 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
95 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
96 wxFLAGS_MEMBER(wxVSCROLL
)
97 wxFLAGS_MEMBER(wxHSCROLL
)
99 wxFLAGS_MEMBER(wxLC_LIST
)
100 wxFLAGS_MEMBER(wxLC_REPORT
)
101 wxFLAGS_MEMBER(wxLC_ICON
)
102 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
103 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
104 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
105 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
106 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
107 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
108 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
109 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
110 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
111 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
112 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
114 wxEND_FLAGS( wxListCtrlStyle
)
116 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
118 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
119 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
121 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
122 wxEND_PROPERTIES_TABLE()
124 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
125 wxEND_HANDLERS_TABLE()
127 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
130 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
133 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
136 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
137 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
139 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
141 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
142 EVT_PAINT(wxListCtrl::OnPaint
)
145 // ============================================================================
147 // ============================================================================
149 // ----------------------------------------------------------------------------
150 // wxListCtrl construction
151 // ----------------------------------------------------------------------------
153 void wxListCtrl::Init()
157 bool wxListCtrl::Create(wxWindow
*parent
,
162 const wxValidator
& validator
,
163 const wxString
& name
)
168 void wxListCtrl::UpdateStyle()
172 void wxListCtrl::FreeAllInternalData()
176 wxListCtrl::~wxListCtrl()
180 // ----------------------------------------------------------------------------
181 // set/get/change style
182 // ----------------------------------------------------------------------------
184 // Add or remove a single window style
185 void wxListCtrl::SetSingleStyle(long style
, bool add
)
189 // ----------------------------------------------------------------------------
191 // ----------------------------------------------------------------------------
193 /* static */ wxVisualAttributes
wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
195 wxVisualAttributes attrs
;
200 // Sets the foreground, i.e. text, colour
201 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
206 // Sets the background colour
207 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
212 // Gets information about this column
213 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
218 // Sets information about this column
219 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
224 // Gets the column width
225 int wxListCtrl::GetColumnWidth(int col
) const
230 // Sets the column width
231 bool wxListCtrl::SetColumnWidth(int col
, int width
)
236 // Gets the number of items that can fit vertically in the
237 // visible area of the list control (list or report view)
238 // or the total number of items in the list control (icon
239 // or small icon view)
240 int wxListCtrl::GetCountPerPage() const
245 // Gets the edit control for editing labels.
246 wxTextCtrl
* wxListCtrl::GetEditControl() const
251 // Gets information about the item
252 bool wxListCtrl::GetItem(wxListItem
& info
) const
257 // Sets information about the item
258 bool wxListCtrl::SetItem(wxListItem
& info
)
263 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
269 // Gets the item state
270 int wxListCtrl::GetItemState(long item
, long stateMask
) const
275 // Sets the item state
276 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
281 // Sets the item image
282 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
287 // Sets the item image
288 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
293 // Gets the item text
294 wxString
wxListCtrl::GetItemText(long item
) const
301 // Sets the item text
302 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
306 // Gets the item data
307 long wxListCtrl::GetItemData(long item
) const
312 // Sets the item data
313 bool wxListCtrl::SetItemData(long item
, long data
)
318 wxRect
wxListCtrl::GetViewRect() const
325 // Gets the item rectangle
326 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
331 // Gets the item position
332 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
337 // Sets the item position.
338 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
343 // Gets the number of items in the list control
344 int wxListCtrl::GetItemCount() const
349 wxSize
wxListCtrl::GetItemSpacing() const
354 int wxListCtrl::GetItemSpacing(bool isSmall
) const
359 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
363 wxColour
wxListCtrl::GetItemTextColour( long item
) const
370 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
374 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
381 // Gets the number of selected items in the list control
382 int wxListCtrl::GetSelectedItemCount() const
387 // Gets the text colour of the listview
388 wxColour
wxListCtrl::GetTextColour() const
394 // Sets the text colour of the listview
395 void wxListCtrl::SetTextColour(const wxColour
& col
)
399 // Gets the index of the topmost visible item when in
400 // list or report view
401 long wxListCtrl::GetTopItem() const
406 // Searches for an item, starting from 'item'.
407 // 'geometry' is one of
408 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
409 // 'state' is a state bit flag, one or more of
410 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
411 // item can be -1 to find the first item that matches the
413 // Returns the item or -1 if unsuccessful.
414 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
420 wxImageList
*wxListCtrl::GetImageList(int which
) const
425 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
429 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
433 // ----------------------------------------------------------------------------
435 // ----------------------------------------------------------------------------
437 // Arranges the items
438 bool wxListCtrl::Arrange(int flag
)
444 bool wxListCtrl::DeleteItem(long item
)
450 bool wxListCtrl::DeleteAllItems()
456 bool wxListCtrl::DeleteAllColumns()
462 bool wxListCtrl::DeleteColumn(int col
)
467 // Clears items, and columns if there are any.
468 void wxListCtrl::ClearAll()
472 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
477 // End label editing, optionally cancelling the edit
478 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
483 // Ensures this item is visible
484 bool wxListCtrl::EnsureVisible(long item
)
489 // Find an item whose label matches this string, starting from the item after 'start'
490 // or the beginning if 'start' is -1.
491 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
496 // Find an item whose data matches this data, starting from the item after 'start'
497 // or the beginning if 'start' is -1.
498 // NOTE : Lindsay Mathieson - 14-July-2002
499 // No longer use ListView_FindItem as the data attribute is now stored
500 // in a wxListItemInternalData structure refernced by the actual lParam
501 long wxListCtrl::FindItem(long start
, long data
)
506 // Find an item nearest this position in the specified direction, starting from
507 // the item after 'start' or the beginning if 'start' is -1.
508 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
513 // Determines which item (if any) is at the specified point,
514 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
515 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
520 // Inserts an item, returning the index of the new item if successful,
522 long wxListCtrl::InsertItem(wxListItem
& info
)
527 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
532 // Inserts an image item
533 long wxListCtrl::InsertItem(long index
, int imageIndex
)
538 // Inserts an image/string item
539 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
544 // For list view mode (only), inserts a column.
545 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
550 long wxListCtrl::InsertColumn(long col
,
551 const wxString
& heading
,
558 // scroll the control by the given number of pixels (exception: in list view,
559 // dx is interpreted as number of columns)
560 bool wxListCtrl::ScrollList(int dx
, int dy
)
567 // fn is a function which takes 3 long arguments: item1, item2, data.
568 // item1 is the long data associated with a first item (NOT the index).
569 // item2 is the long data associated with a second item (NOT the index).
570 // data is the same value as passed to SortItems.
571 // The return value is a negative number if the first item should precede the second
572 // item, a positive number of the second item should precede the first,
573 // or zero if the two items are equivalent.
575 // data is arbitrary data to be passed to the sort function.
577 // Internal structures for proxying the user compare function
578 // so that we can pass it the *real* user data
580 // translate lParam data and call user func
581 struct wxInternalDataSort
583 wxListCtrlCompare user_fn
;
587 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
589 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
591 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
592 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
594 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
595 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
597 return internalData
->user_fn(d1
, d2
, internalData
->data
);
601 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
608 // ----------------------------------------------------------------------------
609 // message processing
610 // ----------------------------------------------------------------------------
612 // Necessary for drawing hrules and vrules, if specified
613 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
617 // ----------------------------------------------------------------------------
618 // virtual list controls
619 // ----------------------------------------------------------------------------
621 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
623 return wxEmptyString
;
626 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
631 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
634 return OnGetItemImage(item
);
639 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
641 // no attributes by default
645 void wxListCtrl::SetItemCount(long count
)
649 void wxListCtrl::RefreshItem(long item
)
653 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
657 // ----------------------------------------------------------------------------
658 // internal data stuff
659 // ----------------------------------------------------------------------------
661 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
666 static wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
668 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
671 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
676 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
680 #endif // wxUSE_LISTCTRL