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"
36 #include "wx/textctrl.h"
37 #include "wx/imaglist.h"
38 #include "wx/listctrl.h"
39 #include "wx/dcclient.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 // Gets the item text
288 wxString
wxListCtrl::GetItemText(long item
) const
295 // Sets the item text
296 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
300 // Gets the item data
301 long wxListCtrl::GetItemData(long item
) const
306 // Sets the item data
307 bool wxListCtrl::SetItemData(long item
, long data
)
312 wxRect
wxListCtrl::GetViewRect() const
319 // Gets the item rectangle
320 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
325 // Gets the item position
326 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
331 // Sets the item position.
332 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
337 // Gets the number of items in the list control
338 int wxListCtrl::GetItemCount() const
343 wxSize
wxListCtrl::GetItemSpacing() const
348 int wxListCtrl::GetItemSpacing(bool isSmall
) const
353 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
357 wxColour
wxListCtrl::GetItemTextColour( long item
) const
364 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
368 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
375 // Gets the number of selected items in the list control
376 int wxListCtrl::GetSelectedItemCount() const
381 // Gets the text colour of the listview
382 wxColour
wxListCtrl::GetTextColour() const
388 // Sets the text colour of the listview
389 void wxListCtrl::SetTextColour(const wxColour
& col
)
393 // Gets the index of the topmost visible item when in
394 // list or report view
395 long wxListCtrl::GetTopItem() const
400 // Searches for an item, starting from 'item'.
401 // 'geometry' is one of
402 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
403 // 'state' is a state bit flag, one or more of
404 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
405 // item can be -1 to find the first item that matches the
407 // Returns the item or -1 if unsuccessful.
408 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
414 wxImageList
*wxListCtrl::GetImageList(int which
) const
419 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
423 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
427 // ----------------------------------------------------------------------------
429 // ----------------------------------------------------------------------------
431 // Arranges the items
432 bool wxListCtrl::Arrange(int flag
)
438 bool wxListCtrl::DeleteItem(long item
)
444 bool wxListCtrl::DeleteAllItems()
450 bool wxListCtrl::DeleteAllColumns()
456 bool wxListCtrl::DeleteColumn(int col
)
461 // Clears items, and columns if there are any.
462 void wxListCtrl::ClearAll()
466 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
471 // End label editing, optionally cancelling the edit
472 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
477 // Ensures this item is visible
478 bool wxListCtrl::EnsureVisible(long item
)
483 // Find an item whose label matches this string, starting from the item after 'start'
484 // or the beginning if 'start' is -1.
485 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
490 // Find an item whose data matches this data, starting from the item after 'start'
491 // or the beginning if 'start' is -1.
492 // NOTE : Lindsay Mathieson - 14-July-2002
493 // No longer use ListView_FindItem as the data attribute is now stored
494 // in a wxListItemInternalData structure refernced by the actual lParam
495 long wxListCtrl::FindItem(long start
, long data
)
500 // Find an item nearest this position in the specified direction, starting from
501 // the item after 'start' or the beginning if 'start' is -1.
502 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
507 // Determines which item (if any) is at the specified point,
508 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
509 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
514 // Inserts an item, returning the index of the new item if successful,
516 long wxListCtrl::InsertItem(wxListItem
& info
)
521 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
526 // Inserts an image item
527 long wxListCtrl::InsertItem(long index
, int imageIndex
)
532 // Inserts an image/string item
533 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
538 // For list view mode (only), inserts a column.
539 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
544 long wxListCtrl::InsertColumn(long col
,
545 const wxString
& heading
,
552 // scroll the control by the given number of pixels (exception: in list view,
553 // dx is interpreted as number of columns)
554 bool wxListCtrl::ScrollList(int dx
, int dy
)
561 // fn is a function which takes 3 long arguments: item1, item2, data.
562 // item1 is the long data associated with a first item (NOT the index).
563 // item2 is the long data associated with a second item (NOT the index).
564 // data is the same value as passed to SortItems.
565 // The return value is a negative number if the first item should precede the second
566 // item, a positive number of the second item should precede the first,
567 // or zero if the two items are equivalent.
569 // data is arbitrary data to be passed to the sort function.
571 // Internal structures for proxying the user compare function
572 // so that we can pass it the *real* user data
574 // translate lParam data and call user func
575 struct wxInternalDataSort
577 wxListCtrlCompare user_fn
;
581 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
583 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
585 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
586 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
588 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
589 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
591 return internalData
->user_fn(d1
, d2
, internalData
->data
);
595 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
602 // ----------------------------------------------------------------------------
603 // message processing
604 // ----------------------------------------------------------------------------
606 // Necessary for drawing hrules and vrules, if specified
607 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
611 // ----------------------------------------------------------------------------
612 // virtual list controls
613 // ----------------------------------------------------------------------------
615 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
617 return wxEmptyString
;
620 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
625 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
628 return OnGetItemImage(item
);
633 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
635 // no attributes by default
639 void wxListCtrl::SetItemCount(long count
)
643 void wxListCtrl::RefreshItem(long item
)
647 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
651 // ----------------------------------------------------------------------------
652 // internal data stuff
653 // ----------------------------------------------------------------------------
655 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
660 static wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
662 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
665 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
670 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
674 #endif // wxUSE_LISTCTRL