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"
32 #if wxUSE_LISTCTRL && defined(__WIN95__)
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 #include "wx/palmos/private.h"
48 #include "wx/palmos/wrapcctl.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
55 // private helper classes
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
67 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
68 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
69 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
70 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
71 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
72 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
73 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
74 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
75 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
76 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
77 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
78 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
79 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
80 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
81 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
82 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
83 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
85 #if wxUSE_EXTENDED_RTTI
86 WX_DEFINE_FLAGS( wxListCtrlStyle
)
88 wxBEGIN_FLAGS( wxListCtrlStyle
)
89 // new style border flags, we put them first to
90 // use them for streaming out
91 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
92 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
93 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
94 wxFLAGS_MEMBER(wxBORDER_RAISED
)
95 wxFLAGS_MEMBER(wxBORDER_STATIC
)
96 wxFLAGS_MEMBER(wxBORDER_NONE
)
98 // old style border flags
99 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
100 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
101 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
102 wxFLAGS_MEMBER(wxRAISED_BORDER
)
103 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
104 wxFLAGS_MEMBER(wxBORDER
)
106 // standard window styles
107 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
108 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
109 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
110 wxFLAGS_MEMBER(wxWANTS_CHARS
)
111 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
112 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
113 wxFLAGS_MEMBER(wxVSCROLL
)
114 wxFLAGS_MEMBER(wxHSCROLL
)
116 wxFLAGS_MEMBER(wxLC_LIST
)
117 wxFLAGS_MEMBER(wxLC_REPORT
)
118 wxFLAGS_MEMBER(wxLC_ICON
)
119 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
120 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
121 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
122 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
123 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
124 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
125 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
126 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
127 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
128 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
129 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
131 wxEND_FLAGS( wxListCtrlStyle
)
133 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
135 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
136 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
138 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
139 wxEND_PROPERTIES_TABLE()
141 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
142 wxEND_HANDLERS_TABLE()
144 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
147 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
150 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
153 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
154 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
156 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
158 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
159 EVT_PAINT(wxListCtrl::OnPaint
)
162 // ============================================================================
164 // ============================================================================
166 // ----------------------------------------------------------------------------
167 // wxListCtrl construction
168 // ----------------------------------------------------------------------------
170 void wxListCtrl::Init()
174 bool wxListCtrl::Create(wxWindow
*parent
,
179 const wxValidator
& validator
,
180 const wxString
& name
)
185 void wxListCtrl::UpdateStyle()
189 void wxListCtrl::FreeAllInternalData()
193 wxListCtrl::~wxListCtrl()
197 // ----------------------------------------------------------------------------
198 // set/get/change style
199 // ----------------------------------------------------------------------------
201 // Add or remove a single window style
202 void wxListCtrl::SetSingleStyle(long style
, bool add
)
206 // Set the whole window style
207 void wxListCtrl::SetWindowStyleFlag(long flag
)
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 /* static */ wxVisualAttributes
216 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
218 wxVisualAttributes attrs
;
223 // Sets the foreground, i.e. text, colour
224 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
229 // Sets the background colour
230 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
235 // Gets information about this column
236 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
241 // Sets information about this column
242 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
247 // Gets the column width
248 int wxListCtrl::GetColumnWidth(int col
) const
253 // Sets the column width
254 bool wxListCtrl::SetColumnWidth(int col
, int width
)
259 // Gets the number of items that can fit vertically in the
260 // visible area of the list control (list or report view)
261 // or the total number of items in the list control (icon
262 // or small icon view)
263 int wxListCtrl::GetCountPerPage() const
268 // Gets the edit control for editing labels.
269 wxTextCtrl
* wxListCtrl::GetEditControl() const
274 // Gets information about the item
275 bool wxListCtrl::GetItem(wxListItem
& info
) const
280 // Sets information about the item
281 bool wxListCtrl::SetItem(wxListItem
& info
)
286 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
292 // Gets the item state
293 int wxListCtrl::GetItemState(long item
, long stateMask
) const
298 // Sets the item state
299 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
304 // Sets the item image
305 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
310 // Gets the item text
311 wxString
wxListCtrl::GetItemText(long item
) const
318 // Sets the item text
319 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
323 // Gets the item data
324 long wxListCtrl::GetItemData(long item
) const
329 // Sets the item data
330 bool wxListCtrl::SetItemData(long item
, long data
)
335 wxRect
wxListCtrl::GetViewRect() const
342 // Gets the item rectangle
343 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
348 // Gets the item position
349 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
354 // Sets the item position.
355 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
360 // Gets the number of items in the list control
361 int wxListCtrl::GetItemCount() const
366 wxSize
wxListCtrl::GetItemSpacing() const
371 int wxListCtrl::GetItemSpacing(bool isSmall
) const
376 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
380 wxColour
wxListCtrl::GetItemTextColour( long item
) const
387 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
391 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
398 // Gets the number of selected items in the list control
399 int wxListCtrl::GetSelectedItemCount() const
404 // Gets the text colour of the listview
405 wxColour
wxListCtrl::GetTextColour() const
411 // Sets the text colour of the listview
412 void wxListCtrl::SetTextColour(const wxColour
& col
)
416 // Gets the index of the topmost visible item when in
417 // list or report view
418 long wxListCtrl::GetTopItem() const
423 // Searches for an item, starting from 'item'.
424 // 'geometry' is one of
425 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
426 // 'state' is a state bit flag, one or more of
427 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
428 // item can be -1 to find the first item that matches the
430 // Returns the item or -1 if unsuccessful.
431 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
437 wxImageList
*wxListCtrl::GetImageList(int which
) const
442 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
446 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
450 // ----------------------------------------------------------------------------
452 // ----------------------------------------------------------------------------
454 // Arranges the items
455 bool wxListCtrl::Arrange(int flag
)
461 bool wxListCtrl::DeleteItem(long item
)
467 bool wxListCtrl::DeleteAllItems()
473 bool wxListCtrl::DeleteAllColumns()
479 bool wxListCtrl::DeleteColumn(int col
)
484 // Clears items, and columns if there are any.
485 void wxListCtrl::ClearAll()
489 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
494 // End label editing, optionally cancelling the edit
495 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
500 // Ensures this item is visible
501 bool wxListCtrl::EnsureVisible(long item
)
506 // Find an item whose label matches this string, starting from the item after 'start'
507 // or the beginning if 'start' is -1.
508 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
513 // Find an item whose data matches this data, starting from the item after 'start'
514 // or the beginning if 'start' is -1.
515 // NOTE : Lindsay Mathieson - 14-July-2002
516 // No longer use ListView_FindItem as the data attribute is now stored
517 // in a wxListItemInternalData structure refernced by the actual lParam
518 long wxListCtrl::FindItem(long start
, long data
)
523 // Find an item nearest this position in the specified direction, starting from
524 // the item after 'start' or the beginning if 'start' is -1.
525 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
530 // Determines which item (if any) is at the specified point,
531 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
532 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
537 // Inserts an item, returning the index of the new item if successful,
539 long wxListCtrl::InsertItem(wxListItem
& info
)
544 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
549 // Inserts an image item
550 long wxListCtrl::InsertItem(long index
, int imageIndex
)
555 // Inserts an image/string item
556 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
561 // For list view mode (only), inserts a column.
562 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
567 long wxListCtrl::InsertColumn(long col
,
568 const wxString
& heading
,
575 // scroll the control by the given number of pixels (exception: in list view,
576 // dx is interpreted as number of columns)
577 bool wxListCtrl::ScrollList(int dx
, int dy
)
584 // fn is a function which takes 3 long arguments: item1, item2, data.
585 // item1 is the long data associated with a first item (NOT the index).
586 // item2 is the long data associated with a second item (NOT the index).
587 // data is the same value as passed to SortItems.
588 // The return value is a negative number if the first item should precede the second
589 // item, a positive number of the second item should precede the first,
590 // or zero if the two items are equivalent.
592 // data is arbitrary data to be passed to the sort function.
594 // Internal structures for proxying the user compare function
595 // so that we can pass it the *real* user data
597 // translate lParam data and call user func
598 struct wxInternalDataSort
600 wxListCtrlCompare user_fn
;
604 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
606 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
608 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
609 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
611 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
612 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
614 return internalData
->user_fn(d1
, d2
, internalData
->data
);
618 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
625 // ----------------------------------------------------------------------------
626 // message processing
627 // ----------------------------------------------------------------------------
629 // see comment at the end of wxListCtrl::GetColumn()
630 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
632 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
634 return CDRF_DODEFAULT
;
637 #endif // NM_CUSTOMDRAW supported
639 // Necessary for drawing hrules and vrules, if specified
640 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
644 // ----------------------------------------------------------------------------
645 // virtual list controls
646 // ----------------------------------------------------------------------------
648 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
650 return wxEmptyString
;
653 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
658 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
660 // no attributes by default
664 void wxListCtrl::SetItemCount(long count
)
668 void wxListCtrl::RefreshItem(long item
)
672 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
676 // ----------------------------------------------------------------------------
677 // internal data stuff
678 // ----------------------------------------------------------------------------
680 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
686 wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
688 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
691 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
696 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
700 #endif // wxUSE_LISTCTRL