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 #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 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
198 /* static */ wxVisualAttributes
wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
200 wxVisualAttributes attrs
;
205 // Sets the foreground, i.e. text, colour
206 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
211 // Sets the background colour
212 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
217 // Gets information about this column
218 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
223 // Sets information about this column
224 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
229 // Gets the column width
230 int wxListCtrl::GetColumnWidth(int col
) const
235 // Sets the column width
236 bool wxListCtrl::SetColumnWidth(int col
, int width
)
241 // Gets the number of items that can fit vertically in the
242 // visible area of the list control (list or report view)
243 // or the total number of items in the list control (icon
244 // or small icon view)
245 int wxListCtrl::GetCountPerPage() const
250 // Gets the edit control for editing labels.
251 wxTextCtrl
* wxListCtrl::GetEditControl() const
256 // Gets information about the item
257 bool wxListCtrl::GetItem(wxListItem
& info
) const
262 // Sets information about the item
263 bool wxListCtrl::SetItem(wxListItem
& info
)
268 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
274 // Gets the item state
275 int wxListCtrl::GetItemState(long item
, long stateMask
) const
280 // Sets the item state
281 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
286 // Sets the item image
287 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
292 // Gets the item text
293 wxString
wxListCtrl::GetItemText(long item
) const
300 // Sets the item text
301 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
305 // Gets the item data
306 long wxListCtrl::GetItemData(long item
) const
311 // Sets the item data
312 bool wxListCtrl::SetItemData(long item
, long data
)
317 wxRect
wxListCtrl::GetViewRect() const
324 // Gets the item rectangle
325 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
330 // Gets the item position
331 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
336 // Sets the item position.
337 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
342 // Gets the number of items in the list control
343 int wxListCtrl::GetItemCount() const
348 wxSize
wxListCtrl::GetItemSpacing() const
353 int wxListCtrl::GetItemSpacing(bool isSmall
) const
358 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
362 wxColour
wxListCtrl::GetItemTextColour( long item
) const
369 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
373 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
380 // Gets the number of selected items in the list control
381 int wxListCtrl::GetSelectedItemCount() const
386 // Gets the text colour of the listview
387 wxColour
wxListCtrl::GetTextColour() const
393 // Sets the text colour of the listview
394 void wxListCtrl::SetTextColour(const wxColour
& col
)
398 // Gets the index of the topmost visible item when in
399 // list or report view
400 long wxListCtrl::GetTopItem() const
405 // Searches for an item, starting from 'item'.
406 // 'geometry' is one of
407 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
408 // 'state' is a state bit flag, one or more of
409 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
410 // item can be -1 to find the first item that matches the
412 // Returns the item or -1 if unsuccessful.
413 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
419 wxImageList
*wxListCtrl::GetImageList(int which
) const
424 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
428 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
432 // ----------------------------------------------------------------------------
434 // ----------------------------------------------------------------------------
436 // Arranges the items
437 bool wxListCtrl::Arrange(int flag
)
443 bool wxListCtrl::DeleteItem(long item
)
449 bool wxListCtrl::DeleteAllItems()
455 bool wxListCtrl::DeleteAllColumns()
461 bool wxListCtrl::DeleteColumn(int col
)
466 // Clears items, and columns if there are any.
467 void wxListCtrl::ClearAll()
471 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
476 // End label editing, optionally cancelling the edit
477 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
482 // Ensures this item is visible
483 bool wxListCtrl::EnsureVisible(long item
)
488 // Find an item whose label matches this string, starting from the item after 'start'
489 // or the beginning if 'start' is -1.
490 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
495 // Find an item whose data matches this data, starting from the item after 'start'
496 // or the beginning if 'start' is -1.
497 // NOTE : Lindsay Mathieson - 14-July-2002
498 // No longer use ListView_FindItem as the data attribute is now stored
499 // in a wxListItemInternalData structure refernced by the actual lParam
500 long wxListCtrl::FindItem(long start
, long data
)
505 // Find an item nearest this position in the specified direction, starting from
506 // the item after 'start' or the beginning if 'start' is -1.
507 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
512 // Determines which item (if any) is at the specified point,
513 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
514 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
519 // Inserts an item, returning the index of the new item if successful,
521 long wxListCtrl::InsertItem(wxListItem
& info
)
526 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
531 // Inserts an image item
532 long wxListCtrl::InsertItem(long index
, int imageIndex
)
537 // Inserts an image/string item
538 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
543 // For list view mode (only), inserts a column.
544 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
549 long wxListCtrl::InsertColumn(long col
,
550 const wxString
& heading
,
557 // scroll the control by the given number of pixels (exception: in list view,
558 // dx is interpreted as number of columns)
559 bool wxListCtrl::ScrollList(int dx
, int dy
)
566 // fn is a function which takes 3 long arguments: item1, item2, data.
567 // item1 is the long data associated with a first item (NOT the index).
568 // item2 is the long data associated with a second item (NOT the index).
569 // data is the same value as passed to SortItems.
570 // The return value is a negative number if the first item should precede the second
571 // item, a positive number of the second item should precede the first,
572 // or zero if the two items are equivalent.
574 // data is arbitrary data to be passed to the sort function.
576 // Internal structures for proxying the user compare function
577 // so that we can pass it the *real* user data
579 // translate lParam data and call user func
580 struct wxInternalDataSort
582 wxListCtrlCompare user_fn
;
586 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
588 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
590 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
591 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
593 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
594 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
596 return internalData
->user_fn(d1
, d2
, internalData
->data
);
600 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
607 // ----------------------------------------------------------------------------
608 // message processing
609 // ----------------------------------------------------------------------------
611 // Necessary for drawing hrules and vrules, if specified
612 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
616 // ----------------------------------------------------------------------------
617 // virtual list controls
618 // ----------------------------------------------------------------------------
620 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
622 return wxEmptyString
;
625 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
630 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
632 // no attributes by default
636 void wxListCtrl::SetItemCount(long count
)
640 void wxListCtrl::RefreshItem(long item
)
644 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
648 // ----------------------------------------------------------------------------
649 // internal data stuff
650 // ----------------------------------------------------------------------------
652 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
657 static wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
659 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
662 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
667 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
671 #endif // wxUSE_LISTCTRL