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 #if wxUSE_EXTENDED_RTTI
42 WX_DEFINE_FLAGS( wxListCtrlStyle
)
44 wxBEGIN_FLAGS( wxListCtrlStyle
)
45 // new style border flags, we put them first to
46 // use them for streaming out
47 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
48 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
49 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
50 wxFLAGS_MEMBER(wxBORDER_RAISED
)
51 wxFLAGS_MEMBER(wxBORDER_STATIC
)
52 wxFLAGS_MEMBER(wxBORDER_NONE
)
54 // old style border flags
55 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
56 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
57 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
58 wxFLAGS_MEMBER(wxRAISED_BORDER
)
59 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
60 wxFLAGS_MEMBER(wxBORDER
)
62 // standard window styles
63 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
64 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
65 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
66 wxFLAGS_MEMBER(wxWANTS_CHARS
)
67 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
68 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
69 wxFLAGS_MEMBER(wxVSCROLL
)
70 wxFLAGS_MEMBER(wxHSCROLL
)
72 wxFLAGS_MEMBER(wxLC_LIST
)
73 wxFLAGS_MEMBER(wxLC_REPORT
)
74 wxFLAGS_MEMBER(wxLC_ICON
)
75 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
76 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
77 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
78 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
79 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
80 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
81 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
82 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
83 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
84 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
85 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
87 wxEND_FLAGS( wxListCtrlStyle
)
89 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
91 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
92 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
94 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
95 wxEND_PROPERTIES_TABLE()
97 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
98 wxEND_HANDLERS_TABLE()
100 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
103 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
106 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
109 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
110 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
112 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
114 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
115 EVT_PAINT(wxListCtrl::OnPaint
)
118 // ============================================================================
120 // ============================================================================
122 // ----------------------------------------------------------------------------
123 // wxListCtrl construction
124 // ----------------------------------------------------------------------------
126 void wxListCtrl::Init()
130 bool wxListCtrl::Create(wxWindow
*parent
,
135 const wxValidator
& validator
,
136 const wxString
& name
)
141 void wxListCtrl::UpdateStyle()
145 void wxListCtrl::FreeAllInternalData()
149 wxListCtrl::~wxListCtrl()
153 // ----------------------------------------------------------------------------
154 // set/get/change style
155 // ----------------------------------------------------------------------------
157 // Add or remove a single window style
158 void wxListCtrl::SetSingleStyle(long style
, bool add
)
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 /* static */ wxVisualAttributes
wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
168 wxVisualAttributes attrs
;
173 // Sets the foreground, i.e. text, colour
174 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
179 // Sets the background colour
180 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
185 // Gets information about this column
186 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
191 // Sets information about this column
192 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
197 // Gets the column width
198 int wxListCtrl::GetColumnWidth(int col
) const
203 // Sets the column width
204 bool wxListCtrl::SetColumnWidth(int col
, int width
)
209 // Gets the number of items that can fit vertically in the
210 // visible area of the list control (list or report view)
211 // or the total number of items in the list control (icon
212 // or small icon view)
213 int wxListCtrl::GetCountPerPage() const
218 // Gets the edit control for editing labels.
219 wxTextCtrl
* wxListCtrl::GetEditControl() const
224 // Gets information about the item
225 bool wxListCtrl::GetItem(wxListItem
& info
) const
230 // Sets information about the item
231 bool wxListCtrl::SetItem(wxListItem
& info
)
236 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
242 // Gets the item state
243 int wxListCtrl::GetItemState(long item
, long stateMask
) const
248 // Sets the item state
249 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
254 // Sets the item image
255 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
260 // Sets the item image
261 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
266 // Gets the item text
267 wxString
wxListCtrl::GetItemText(long item
) const
274 // Sets the item text
275 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
279 // Gets the item data
280 long wxListCtrl::GetItemData(long item
) const
285 // Sets the item data
286 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
291 wxRect
wxListCtrl::GetViewRect() const
298 // Gets the item rectangle
299 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
304 // Gets the item position
305 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
310 // Sets the item position.
311 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
316 // Gets the number of items in the list control
317 int wxListCtrl::GetItemCount() const
322 wxSize
wxListCtrl::GetItemSpacing() const
327 int wxListCtrl::GetItemSpacing(bool isSmall
) const
332 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
336 wxColour
wxListCtrl::GetItemTextColour( long item
) const
343 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
347 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
354 // Gets the number of selected items in the list control
355 int wxListCtrl::GetSelectedItemCount() const
360 // Gets the text colour of the listview
361 wxColour
wxListCtrl::GetTextColour() const
367 // Sets the text colour of the listview
368 void wxListCtrl::SetTextColour(const wxColour
& col
)
372 // Gets the index of the topmost visible item when in
373 // list or report view
374 long wxListCtrl::GetTopItem() const
379 // Searches for an item, starting from 'item'.
380 // 'geometry' is one of
381 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
382 // 'state' is a state bit flag, one or more of
383 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
384 // item can be -1 to find the first item that matches the
386 // Returns the item or -1 if unsuccessful.
387 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
393 wxImageList
*wxListCtrl::GetImageList(int which
) const
398 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
402 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
406 // ----------------------------------------------------------------------------
408 // ----------------------------------------------------------------------------
410 // Arranges the items
411 bool wxListCtrl::Arrange(int flag
)
417 bool wxListCtrl::DeleteItem(long item
)
423 bool wxListCtrl::DeleteAllItems()
429 bool wxListCtrl::DeleteAllColumns()
435 bool wxListCtrl::DeleteColumn(int col
)
440 // Clears items, and columns if there are any.
441 void wxListCtrl::ClearAll()
445 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
450 // End label editing, optionally cancelling the edit
451 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
456 // Ensures this item is visible
457 bool wxListCtrl::EnsureVisible(long item
)
462 // Find an item whose label matches this string, starting from the item after 'start'
463 // or the beginning if 'start' is -1.
464 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
469 // Find an item whose data matches this data, starting from the item after 'start'
470 // or the beginning if 'start' is -1.
471 // NOTE : Lindsay Mathieson - 14-July-2002
472 // No longer use ListView_FindItem as the data attribute is now stored
473 // in a wxListItemInternalData structure refernced by the actual lParam
474 long wxListCtrl::FindItem(long start
, long data
)
479 // Find an item nearest this position in the specified direction, starting from
480 // the item after 'start' or the beginning if 'start' is -1.
481 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
486 // Determines which item (if any) is at the specified point,
487 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
488 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
493 // Inserts an item, returning the index of the new item if successful,
495 long wxListCtrl::InsertItem(wxListItem
& info
)
500 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
505 // Inserts an image item
506 long wxListCtrl::InsertItem(long index
, int imageIndex
)
511 // Inserts an image/string item
512 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
517 // For list view mode (only), inserts a column.
518 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
523 long wxListCtrl::InsertColumn(long col
,
524 const wxString
& heading
,
531 // scroll the control by the given number of pixels (exception: in list view,
532 // dx is interpreted as number of columns)
533 bool wxListCtrl::ScrollList(int dx
, int dy
)
540 // fn is a function which takes 3 long arguments: item1, item2, data.
541 // item1 is the long data associated with a first item (NOT the index).
542 // item2 is the long data associated with a second item (NOT the index).
543 // data is the same value as passed to SortItems.
544 // The return value is a negative number if the first item should precede the second
545 // item, a positive number of the second item should precede the first,
546 // or zero if the two items are equivalent.
548 // data is arbitrary data to be passed to the sort function.
550 // Internal structures for proxying the user compare function
551 // so that we can pass it the *real* user data
553 // translate lParam data and call user func
554 struct wxInternalDataSort
556 wxListCtrlCompare user_fn
;
560 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
562 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
564 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
565 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
567 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
568 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
570 return internalData
->user_fn(d1
, d2
, internalData
->data
);
574 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
581 // ----------------------------------------------------------------------------
582 // message processing
583 // ----------------------------------------------------------------------------
585 // Necessary for drawing hrules and vrules, if specified
586 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
590 // ----------------------------------------------------------------------------
591 // virtual list controls
592 // ----------------------------------------------------------------------------
594 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
596 return wxEmptyString
;
599 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
604 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
607 return OnGetItemImage(item
);
612 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
614 // no attributes by default
618 void wxListCtrl::SetItemCount(long count
)
622 void wxListCtrl::RefreshItem(long item
)
626 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
630 // ----------------------------------------------------------------------------
631 // internal data stuff
632 // ----------------------------------------------------------------------------
634 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
639 static wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
641 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
644 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
649 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
653 #endif // wxUSE_LISTCTRL