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 WXDWORD
wxListCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
190 void wxListCtrl::UpdateStyle()
194 void wxListCtrl::FreeAllInternalData()
198 wxListCtrl::~wxListCtrl()
202 // ----------------------------------------------------------------------------
203 // set/get/change style
204 // ----------------------------------------------------------------------------
206 // Add or remove a single window style
207 void wxListCtrl::SetSingleStyle(long style
, bool add
)
211 // Set the whole window style
212 void wxListCtrl::SetWindowStyleFlag(long flag
)
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 /* static */ wxVisualAttributes
221 wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
223 wxVisualAttributes attrs
;
228 // Sets the foreground, i.e. text, colour
229 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
234 // Sets the background colour
235 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
240 // Gets information about this column
241 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
246 // Sets information about this column
247 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
252 // Gets the column width
253 int wxListCtrl::GetColumnWidth(int col
) const
258 // Sets the column width
259 bool wxListCtrl::SetColumnWidth(int col
, int width
)
264 // Gets the number of items that can fit vertically in the
265 // visible area of the list control (list or report view)
266 // or the total number of items in the list control (icon
267 // or small icon view)
268 int wxListCtrl::GetCountPerPage() const
273 // Gets the edit control for editing labels.
274 wxTextCtrl
* wxListCtrl::GetEditControl() const
279 // Gets information about the item
280 bool wxListCtrl::GetItem(wxListItem
& info
) const
285 // Sets information about the item
286 bool wxListCtrl::SetItem(wxListItem
& info
)
291 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
297 // Gets the item state
298 int wxListCtrl::GetItemState(long item
, long stateMask
) const
303 // Sets the item state
304 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
309 // Sets the item image
310 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
315 // Gets the item text
316 wxString
wxListCtrl::GetItemText(long item
) const
323 // Sets the item text
324 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
328 // Gets the item data
329 long wxListCtrl::GetItemData(long item
) const
334 // Sets the item data
335 bool wxListCtrl::SetItemData(long item
, long data
)
340 wxRect
wxListCtrl::GetViewRect() const
347 // Gets the item rectangle
348 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
353 // Gets the item position
354 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
359 // Sets the item position.
360 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
365 // Gets the number of items in the list control
366 int wxListCtrl::GetItemCount() const
371 wxSize
wxListCtrl::GetItemSpacing() const
376 int wxListCtrl::GetItemSpacing(bool isSmall
) const
381 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
385 wxColour
wxListCtrl::GetItemTextColour( long item
) const
392 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
396 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
403 // Gets the number of selected items in the list control
404 int wxListCtrl::GetSelectedItemCount() const
409 // Gets the text colour of the listview
410 wxColour
wxListCtrl::GetTextColour() const
416 // Sets the text colour of the listview
417 void wxListCtrl::SetTextColour(const wxColour
& col
)
421 // Gets the index of the topmost visible item when in
422 // list or report view
423 long wxListCtrl::GetTopItem() const
428 // Searches for an item, starting from 'item'.
429 // 'geometry' is one of
430 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
431 // 'state' is a state bit flag, one or more of
432 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
433 // item can be -1 to find the first item that matches the
435 // Returns the item or -1 if unsuccessful.
436 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
442 wxImageList
*wxListCtrl::GetImageList(int which
) const
447 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
451 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
455 // ----------------------------------------------------------------------------
457 // ----------------------------------------------------------------------------
459 // Arranges the items
460 bool wxListCtrl::Arrange(int flag
)
466 bool wxListCtrl::DeleteItem(long item
)
472 bool wxListCtrl::DeleteAllItems()
478 bool wxListCtrl::DeleteAllColumns()
484 bool wxListCtrl::DeleteColumn(int col
)
489 // Clears items, and columns if there are any.
490 void wxListCtrl::ClearAll()
494 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
499 // End label editing, optionally cancelling the edit
500 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
505 // Ensures this item is visible
506 bool wxListCtrl::EnsureVisible(long item
)
511 // Find an item whose label matches this string, starting from the item after 'start'
512 // or the beginning if 'start' is -1.
513 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
518 // Find an item whose data matches this data, starting from the item after 'start'
519 // or the beginning if 'start' is -1.
520 // NOTE : Lindsay Mathieson - 14-July-2002
521 // No longer use ListView_FindItem as the data attribute is now stored
522 // in a wxListItemInternalData structure refernced by the actual lParam
523 long wxListCtrl::FindItem(long start
, long data
)
528 // Find an item nearest this position in the specified direction, starting from
529 // the item after 'start' or the beginning if 'start' is -1.
530 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
535 // Determines which item (if any) is at the specified point,
536 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
537 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
542 // Inserts an item, returning the index of the new item if successful,
544 long wxListCtrl::InsertItem(wxListItem
& info
)
549 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
554 // Inserts an image item
555 long wxListCtrl::InsertItem(long index
, int imageIndex
)
560 // Inserts an image/string item
561 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
566 // For list view mode (only), inserts a column.
567 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
572 long wxListCtrl::InsertColumn(long col
,
573 const wxString
& heading
,
580 // scroll the control by the given number of pixels (exception: in list view,
581 // dx is interpreted as number of columns)
582 bool wxListCtrl::ScrollList(int dx
, int dy
)
589 // fn is a function which takes 3 long arguments: item1, item2, data.
590 // item1 is the long data associated with a first item (NOT the index).
591 // item2 is the long data associated with a second item (NOT the index).
592 // data is the same value as passed to SortItems.
593 // The return value is a negative number if the first item should precede the second
594 // item, a positive number of the second item should precede the first,
595 // or zero if the two items are equivalent.
597 // data is arbitrary data to be passed to the sort function.
599 // Internal structures for proxying the user compare function
600 // so that we can pass it the *real* user data
602 // translate lParam data and call user func
603 struct wxInternalDataSort
605 wxListCtrlCompare user_fn
;
609 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
611 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
613 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
614 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
616 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
617 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
619 return internalData
->user_fn(d1
, d2
, internalData
->data
);
623 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
630 // ----------------------------------------------------------------------------
631 // message processing
632 // ----------------------------------------------------------------------------
634 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
639 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
644 // see comment at the end of wxListCtrl::GetColumn()
645 #ifdef NM_CUSTOMDRAW // _WIN32_IE >= 0x0300
647 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
649 return CDRF_DODEFAULT
;
652 #endif // NM_CUSTOMDRAW supported
654 // Necessary for drawing hrules and vrules, if specified
655 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
659 // ----------------------------------------------------------------------------
660 // virtual list controls
661 // ----------------------------------------------------------------------------
663 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
665 return wxEmptyString
;
668 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
673 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
675 // no attributes by default
679 void wxListCtrl::SetItemCount(long count
)
683 void wxListCtrl::RefreshItem(long item
)
687 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
691 // ----------------------------------------------------------------------------
692 // internal data stuff
693 // ----------------------------------------------------------------------------
695 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
701 wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
703 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
706 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
711 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
715 // ----------------------------------------------------------------------------
716 // wxWin <-> MSW items conversions
717 // ----------------------------------------------------------------------------
719 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
725 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
729 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
730 const wxListItem
& info
,
735 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
740 #endif // wxUSE_LISTCTRL