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 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
42 EVT_PAINT(wxListCtrl::OnPaint
)
45 // ============================================================================
47 // ============================================================================
49 // ----------------------------------------------------------------------------
50 // wxListCtrl construction
51 // ----------------------------------------------------------------------------
53 void wxListCtrl::Init()
57 bool wxListCtrl::Create(wxWindow
*parent
,
62 const wxValidator
& validator
,
68 void wxListCtrl::UpdateStyle()
72 void wxListCtrl::FreeAllInternalData()
76 wxListCtrl::~wxListCtrl()
80 // ----------------------------------------------------------------------------
81 // set/get/change style
82 // ----------------------------------------------------------------------------
84 // Add or remove a single window style
85 void wxListCtrl::SetSingleStyle(long style
, bool add
)
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 /* static */ wxVisualAttributes
wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
95 wxVisualAttributes attrs
;
100 // Sets the foreground, i.e. text, colour
101 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
106 // Sets the background colour
107 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
112 // Gets information about this column
113 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
118 // Sets information about this column
119 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
124 // Gets the column width
125 int wxListCtrl::GetColumnWidth(int col
) const
130 // Sets the column width
131 bool wxListCtrl::SetColumnWidth(int col
, int width
)
136 // Gets the number of items that can fit vertically in the
137 // visible area of the list control (list or report view)
138 // or the total number of items in the list control (icon
139 // or small icon view)
140 int wxListCtrl::GetCountPerPage() const
145 // Gets the edit control for editing labels.
146 wxTextCtrl
* wxListCtrl::GetEditControl() const
151 // Gets information about the item
152 bool wxListCtrl::GetItem(wxListItem
& info
) const
157 // Sets information about the item
158 bool wxListCtrl::SetItem(wxListItem
& info
)
163 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
169 // Gets the item state
170 int wxListCtrl::GetItemState(long item
, long stateMask
) const
175 // Sets the item state
176 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
181 // Sets the item image
182 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
187 // Sets the item image
188 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
193 // Gets the item text
194 wxString
wxListCtrl::GetItemText(long item
) const
201 // Sets the item text
202 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
206 // Gets the item data
207 long wxListCtrl::GetItemData(long item
) const
212 // Sets the item data
213 bool wxListCtrl::SetItemPtrData(long item
, wxUIntPtr data
)
218 wxRect
wxListCtrl::GetViewRect() const
225 // Gets the item rectangle
226 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
231 // Gets the item position
232 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
237 // Sets the item position.
238 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
243 // Gets the number of items in the list control
244 int wxListCtrl::GetItemCount() const
249 wxSize
wxListCtrl::GetItemSpacing() const
254 int wxListCtrl::GetItemSpacing(bool isSmall
) const
259 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
263 wxColour
wxListCtrl::GetItemTextColour( long item
) const
270 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
274 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
281 // Gets the number of selected items in the list control
282 int wxListCtrl::GetSelectedItemCount() const
287 // Gets the text colour of the listview
288 wxColour
wxListCtrl::GetTextColour() const
294 // Sets the text colour of the listview
295 void wxListCtrl::SetTextColour(const wxColour
& col
)
299 // Gets the index of the topmost visible item when in
300 // list or report view
301 long wxListCtrl::GetTopItem() const
306 // Searches for an item, starting from 'item'.
307 // 'geometry' is one of
308 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
309 // 'state' is a state bit flag, one or more of
310 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
311 // item can be -1 to find the first item that matches the
313 // Returns the item or -1 if unsuccessful.
314 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
320 wxImageList
*wxListCtrl::GetImageList(int which
) const
325 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
329 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
333 // ----------------------------------------------------------------------------
335 // ----------------------------------------------------------------------------
337 // Arranges the items
338 bool wxListCtrl::Arrange(int flag
)
344 bool wxListCtrl::DeleteItem(long item
)
350 bool wxListCtrl::DeleteAllItems()
356 bool wxListCtrl::DeleteAllColumns()
362 bool wxListCtrl::DeleteColumn(int col
)
367 // Clears items, and columns if there are any.
368 void wxListCtrl::ClearAll()
372 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
377 // End label editing, optionally cancelling the edit
378 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
383 // Ensures this item is visible
384 bool wxListCtrl::EnsureVisible(long item
)
389 // Find an item whose label matches this string, starting from the item after 'start'
390 // or the beginning if 'start' is -1.
391 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
396 // Find an item whose data matches this data, starting from the item after 'start'
397 // or the beginning if 'start' is -1.
398 // NOTE : Lindsay Mathieson - 14-July-2002
399 // No longer use ListView_FindItem as the data attribute is now stored
400 // in a wxListItemInternalData structure refernced by the actual lParam
401 long wxListCtrl::FindItem(long start
, long data
)
406 // Find an item nearest this position in the specified direction, starting from
407 // the item after 'start' or the beginning if 'start' is -1.
408 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
413 // Determines which item (if any) is at the specified point,
414 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
415 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
420 // Inserts an item, returning the index of the new item if successful,
422 long wxListCtrl::InsertItem(wxListItem
& info
)
427 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
432 // Inserts an image item
433 long wxListCtrl::InsertItem(long index
, int imageIndex
)
438 // Inserts an image/string item
439 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
444 // For list view mode (only), inserts a column.
445 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
450 long wxListCtrl::InsertColumn(long col
,
451 const wxString
& heading
,
458 // scroll the control by the given number of pixels (exception: in list view,
459 // dx is interpreted as number of columns)
460 bool wxListCtrl::ScrollList(int dx
, int dy
)
467 // fn is a function which takes 3 long arguments: item1, item2, data.
468 // item1 is the long data associated with a first item (NOT the index).
469 // item2 is the long data associated with a second item (NOT the index).
470 // data is the same value as passed to SortItems.
471 // The return value is a negative number if the first item should precede the second
472 // item, a positive number of the second item should precede the first,
473 // or zero if the two items are equivalent.
475 // data is arbitrary data to be passed to the sort function.
477 // Internal structures for proxying the user compare function
478 // so that we can pass it the *real* user data
480 // translate lParam data and call user func
481 struct wxInternalDataSort
483 wxListCtrlCompare user_fn
;
487 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
489 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
491 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
492 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
494 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
495 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
497 return internalData
->user_fn(d1
, d2
, internalData
->data
);
501 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
508 // ----------------------------------------------------------------------------
509 // message processing
510 // ----------------------------------------------------------------------------
512 // Necessary for drawing hrules and vrules, if specified
513 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
517 // ----------------------------------------------------------------------------
518 // virtual list controls
519 // ----------------------------------------------------------------------------
521 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
523 return wxEmptyString
;
526 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
531 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
534 return OnGetItemImage(item
);
539 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
541 // no attributes by default
545 void wxListCtrl::SetItemCount(long count
)
549 void wxListCtrl::RefreshItem(long item
)
553 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
557 // ----------------------------------------------------------------------------
558 // internal data stuff
559 // ----------------------------------------------------------------------------
561 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
566 static wxListItemInternalData
*wxGetInternalData(const wxListCtrl
*ctl
, long itemId
)
568 return wxGetInternalData(GetHwndOf(ctl
), itemId
);
571 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
576 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
580 #endif // wxUSE_LISTCTRL