From 97c611f84745e193ac2b156a92dd127aaa9c7d51 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Feb 2004 15:02:22 +0000 Subject: [PATCH] fixed and documented GetItemText/BackgroundColour() (closes bug 812907) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25635 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/listctrl.tex | 99 ++++++++++++ src/msw/listctrl.cpp | 307 +++++++++++++------------------------ 3 files changed, 208 insertions(+), 199 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9e8e4130e0..1c04fd1f17 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -155,6 +155,7 @@ wxMSW: - fixed several bugs in wxNotebook with wxNB_MULTILINE style - accelerators are now initially hidden if appropriate (Peter Nielsen) - background colour of a wxComboBox may now be set +- fixed wxListCtrl::GetItemText/BackgroundColour() wxGTK: diff --git a/docs/latex/wx/listctrl.tex b/docs/latex/wx/listctrl.tex index 03cd4fd808..a8398da8a2 100644 --- a/docs/latex/wx/listctrl.tex +++ b/docs/latex/wx/listctrl.tex @@ -103,6 +103,7 @@ functions that take a \helpref{wxListEvent}{wxlistevent} argument. \latexignore{\rtfignore{\wxheading{Members}}} + \membersection{wxListCtrl::wxListCtrl}\label{wxlistctrlconstr} \func{}{wxListCtrl}{\void} @@ -136,12 +137,14 @@ appropriately.} \helpref{wxListCtrl::Create}{wxlistctrlcreate}, \helpref{wxValidator}{wxvalidator} + \membersection{wxListCtrl::\destruct{wxListCtrl}} \func{void}{\destruct{wxListCtrl}}{\void} Destructor, destroying the list control. + \membersection{wxListCtrl::Arrange}\label{wxlistctrlarrange} \func{bool}{Arrange}{\param{int }{flag = wxLIST\_ALIGN\_DEFAULT}} @@ -156,6 +159,7 @@ Arranges the items in icon or small icon view. This only has effect on Win32. {\ \twocolitem{wxLIST\_ALIGN\_SNAP\_TO\_GRID}{Snap to grid.} \end{twocollist} + \membersection{wxListCtrl::AssignImageList}\label{wxlistctrlassignimagelist} \func{void}{AssignImageList}{\param{wxImageList*}{ imageList}, \param{int }{which}} @@ -169,12 +173,14 @@ wxIMAGE\_LIST\_NORMAL, wxIMAGE\_LIST\_SMALL, wxIMAGE\_LIST\_STATE (the last is u \helpref{wxListCtrl::SetImageList}{wxlistctrlsetimagelist} + \membersection{wxListCtrl::ClearAll}\label{wxlistctrlclearall} \func{void}{ClearAll}{} Deletes all items and all columns. + \membersection{wxListCtrl::Create}\label{wxlistctrlcreate} \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp @@ -183,6 +189,7 @@ Deletes all items and all columns. Creates the list control. See \helpref{wxListCtrl::wxListCtrl}{wxlistctrlconstr} for further details. + \membersection{wxListCtrl::DeleteAllItems}\label{wxlistctrldeleteallitems} \func{bool}{DeleteAllItems}{} @@ -193,12 +200,14 @@ Deletes all the items in the list control. {\tt wxEVT\_COMMAND\_LIST\_DELETE\_ITEM} event because deleting many items from the control would be too slow then (unlike \helpref{DeleteItem}{wxlistctrldeleteitem}). + \membersection{wxListCtrl::DeleteColumn}\label{wxlistctrldeletecolumn} \func{bool}{DeleteColumn}{\param{int }{col}} Deletes a column. + \membersection{wxListCtrl::DeleteItem}\label{wxlistctrldeleteitem} \func{bool}{DeleteItem}{\param{long }{item}} @@ -208,6 +217,7 @@ Deletes the specified item. This function sends the See also: \helpref{DeleteAllItems}{wxlistctrldeleteallitems} + \membersection{wxListCtrl::EditLabel}\label{wxlistctrledit} \func{void}{EditLabel}{\param{long }{item}} @@ -220,12 +230,14 @@ If the user changed the label (i.e. s/he does not press ESC or leave the text control without changes, a EVT\_LIST\_END\_LABEL\_EDIT event will be sent which can be vetoed as well. + \membersection{wxListCtrl::EnsureVisible}\label{wxlistctrlensurevisible} \func{bool}{EnsureVisible}{\param{long }{item}} Ensures this item is visible. + \membersection{wxListCtrl::FindItem}\label{wxlistctrlfinditem} \func{long}{FindItem}{\param{long }{start}, \param{const wxString\& }{str}, \param{const bool }{partial = false}} @@ -261,6 +273,7 @@ method:\par \end{twocollist} }} + \membersection{wxListCtrl::GetColumn}\label{wxlistctrlgetcolumn} \constfunc{bool}{GetColumn}{\param{int }{col}, \param{wxListItem\& }{item}} @@ -271,18 +284,21 @@ information. \perlnote{In wxPerl this method takes only the {\bf col} parameter and returns a Wx::ListItem ( or undef ).} + \membersection{wxListCtrl::GetColumnCount}\label{wxlistctrlgetcolumncount} \constfunc{int}{GetColumnCount}{\void} Returns the number of columns. + \membersection{wxListCtrl::GetColumnWidth}\label{wxlistctrlgetcolumnwidth} \constfunc{int}{GetColumnWidth}{\param{int }{col}} Gets the column width (report view only). + \membersection{wxListCtrl::GetCountPerPage}\label{wxlistctrlgetcountperpage} \constfunc{int}{GetCountPerPage}{\void} @@ -292,6 +308,7 @@ visible area of the list control (list or report view) or the total number of items in the list control (icon or small icon view). + \membersection{wxListCtrl::GetEditControl}\label{wxlistctrlgeteditcontrol} \constfunc{wxTextCtrl *}{GetEditControl}{\void} @@ -301,6 +318,7 @@ if no label is being edited. {\bf NB:} It is currently only implemented for wxMSW. + \membersection{wxListCtrl::GetImageList}\label{wxlistctrlgetimagelist} \constfunc{wxImageList*}{GetImageList}{\param{int }{which}} @@ -314,6 +332,7 @@ Returns the specified image list. {\it which} may be one of: \twocolitem{\windowstyle{wxIMAGE\_LIST\_STATE}}{The user-defined state image list (unimplemented).} \end{twocollist} + \membersection{wxListCtrl::GetItem}\label{wxlistctrlgetitem} \constfunc{bool}{GetItem}{\param{wxListItem\& }{info}} @@ -331,18 +350,34 @@ returns the wxListItem object.} \perlnote{In wxPerl this method takes as parameter the {\bf ID} of the item and ( optionally ) the column, and returns a Wx::ListItem object.} + +\membersection{wxListCtrl::GetItemBackgroundColour}\label{wxlistctrlgetitembackgroundcolour} + +\constfunc{wxColour}{GetItemBackgroundColour}{\param{long }{item}} + +Returns the colour for this item. If the item has no specific colour, returns +an invalid colour (and not the default background control of the control +itself). + +\wxheading{See also} + +\helpref{GetItemTextColour}{wxlistctrlgetitemtextcolour} + + \membersection{wxListCtrl::GetItemCount}\label{wxlistctrlgetitemcount} \constfunc{int}{GetItemCount}{\void} Returns the number of items in the list control. + \membersection{wxListCtrl::GetItemData}\label{wxlistctrlgetitemdata} \constfunc{long}{GetItemData}{\param{long }{item}} Gets the application-defined data associated with this item. + \membersection{wxListCtrl::GetItemPosition}\label{wxlistctrlgetitemposition} \constfunc{bool}{GetItemPosition}{\param{long }{item}, \param{wxPoint\& }{pos}} @@ -355,6 +390,7 @@ ID and returns the wxPoint.} \perlnote{In wxPerl this method takes only the {\bf item} parameter and returns a Wx::Point ( or undef ).} + \membersection{wxListCtrl::GetItemRect}\label{wxlistctrlgetitemrect} \constfunc{bool}{GetItemRect}{\param{long }{item}, \param{wxRect\& }{rect}, \param{int }{code = wxLIST\_RECT\_BOUNDS}} @@ -370,6 +406,7 @@ ID and code and returns the wxRect.} returns a Wx::Rect ( or undef ).} + \membersection{wxListCtrl::GetItemSpacing}\label{wxlistctrlgetitemspacing} \constfunc{wxSize}{GetItemSpacing}{\void} @@ -379,6 +416,7 @@ as \texttt{x} component of the \helpref{wxSize}{wxsize} object and the vertical spacing as its \texttt{y} component. + \membersection{wxListCtrl::GetItemState}\label{wxlistctrlgetitemstate} \constfunc{int}{GetItemState}{\param{long }{item}, \param{long }{stateMask}} @@ -387,12 +425,25 @@ Gets the item state. For a list of state flags, see \helpref{wxListCtrl::SetItem The {\bf stateMask} indicates which state flags are of interest. + \membersection{wxListCtrl::GetItemText}\label{wxlistctrlgetitemtext} \constfunc{wxString}{GetItemText}{\param{long }{item}} Gets the item text for this item. + +\membersection{wxListCtrl::GetItemTextColour}\label{wxlistctrlgetitemtextcolour} + +\constfunc{wxColour}{GetItemTextColour}{\param{long }{item}} + +Returns the colour for this item. If the item has no specific colour, returns +an invalid colour (and not the default foreground control of the control itself +as this wouldn't allow distinguishing between items having the same colour as +the current control foreground and items with default colour which, hence, have +always the same colour as the control). + + \membersection{wxListCtrl::GetNextItem}\label{wxlistctrlgetnextitem} \constfunc{long}{GetNextItem}{\param{long }{item}, \param{int }{geometry = wxLIST\_NEXT\_ALL}, \param{int }{state = wxLIST\_STATE\_DONTCARE}} @@ -446,18 +497,21 @@ other platforms. \twocolitem{wxLIST\_STATE\_CUT}{The item is selected as part of a cut and paste operation.} \end{twocollist} + \membersection{wxListCtrl::GetSelectedItemCount}\label{wxlistctrlgetselecteditemcount} \constfunc{int}{GetSelectedItemCount}{\void} Returns the number of selected items in the list control. + \membersection{wxListCtrl::GetTextColour}\label{wxlistctrlgettextcolour} \constfunc{wxColour}{GetTextColour}{\void} Gets the text colour of the list control. + \membersection{wxListCtrl::GetTopItem}\label{wxlistctrlgettopitem} \constfunc{long}{GetTopItem}{\void} @@ -466,6 +520,7 @@ Gets the index of the topmost visible item when in list or report view. + \membersection{wxRect}{wxListCtrl::GetViewRect}\label{wxlistctrlgetviewrect} \constfunc{wxRect}{GetViewRect}{\void} @@ -478,6 +533,7 @@ Note that this function only works in the icon and small icon views, not in list or report views (this is a limitation of the native Win32 control). + \membersection{wxListCtrl::HitTest}\label{wxlistctrlhittest} \func{long}{HitTest}{\param{const wxPoint\& }{point}, \param{int\& }{flags}} @@ -507,6 +563,7 @@ flags value mentioned above.} \perlnote{In wxPerl this method only takes the {\bf point} parameter and returns a 2-element list {\tt ( item, flags )}.} + \membersection{wxListCtrl::InsertColumn}\label{wxlistctrlinsertcolumn} \func{long}{InsertColumn}{\param{long }{col}, \param{wxListItem\& }{info}} @@ -526,6 +583,7 @@ wxListInfo.} \end{twocollist}} } + \membersection{wxListCtrl::InsertItem}\label{wxlistctrlinsertitem} \func{long}{InsertItem}{\param{wxListItem\& }{info}} @@ -576,6 +634,7 @@ method:\par \end{twocollist} }} + \membersection{wxListCtrl::OnGetItemAttr}\label{wxlistctrlongetitemattr} \func{virtual wxListItemAttr *}{OnGetItemAttr}{\param{long }{item}} @@ -592,6 +651,7 @@ The base class version always returns {\tt NULL}. \helpref{OnGetItemImage}{wxlistctrlongetitemimage},\\ \helpref{OnGetItemText}{wxlistctrlongetitemtext} + \membersection{wxListCtrl::OnGetItemImage}\label{wxlistctrlongetitemimage} \func{virtual int}{OnGetItemImage}{\param{long }{item}} @@ -609,6 +669,7 @@ The base class version always returns $-1$. \helpref{OnGetItemText}{wxlistctrlongetitemtext},\\ \helpref{OnGetItemAttr}{wxlistctrlongetitemattr} + \membersection{wxListCtrl::OnGetItemText}\label{wxlistctrlongetitemtext} \func{virtual wxString}{OnGetItemText}{\param{long }{item}, \param{long }{column}} @@ -623,6 +684,7 @@ the given {\it column} for the specified {\tt item}. \helpref{OnGetItemImage}{wxlistctrlongetitemimage},\\ \helpref{OnGetItemAttr}{wxlistctrlongetitemattr} + \membersection{wxListCtrl::RefreshItem}\label{wxlistctrlrefreshitem} \func{void}{RefreshItem}{\param{long }{item}} @@ -636,6 +698,7 @@ even when the underlying data does change. \helpref{RefreshItems}{wxlistctrlrefreshitems} + \membersection{wxListCtrl::RefreshItems}\label{wxlistctrlrefreshitems} \func{void}{RefreshItems}{\param{long }{itemFrom}, \param{long }{itemTo}} @@ -647,6 +710,7 @@ Just as \helpref{RefreshItem}{wxlistctrlrefreshitem} this is only useful for virtual list controls. + \membersection{wxListCtrl::ScrollList}\label{wxlistctrlscrolllist} \func{bool}{ScrollList}{\param{int }{dx}, \param{int }{dy}} @@ -658,6 +722,7 @@ the number of pixels to scroll vertically. {\bf NB:} This method is currently only implemented in the Windows version. + \membersection{wxListCtrl::SetBackgroundColour}\label{wxlistctrlsetbackgroundcolour} \func{void}{SetBackgroundColour}{\param{const wxColour\& }{col}} @@ -665,6 +730,7 @@ the number of pixels to scroll vertically. Sets the background colour (GetBackgroundColour already implicit in wxWindow class). + \membersection{wxListCtrl::SetColumn}\label{wxlistctrlsetcolumn} \func{bool}{SetColumn}{\param{int }{col}, \param{wxListItem\& }{item}} @@ -672,6 +738,7 @@ wxWindow class). Sets information about this column. See \helpref{wxListCtrl::SetItem}{wxlistctrlsetitem} for more information. + \membersection{wxListCtrl::SetColumnWidth}\label{wxlistctrlsetcolumnwidth} \func{bool}{SetColumnWidth}{\param{int }{col}, \param{int }{width}} @@ -684,6 +751,7 @@ will resize the column to the length of the header (Win32) or 80 pixels (other p In small or normal icon view, {\it col} must be -1, and the column width is set for all columns. + \membersection{wxListCtrl::SetImageList}\label{wxlistctrlsetimagelist} \func{void}{SetImageList}{\param{wxImageList*}{ imageList}, \param{int }{which}} @@ -699,6 +767,7 @@ delete it yourself. \helpref{wxListCtrl::AssignImageList}{wxlistctrlassignimagelist} + \membersection{wxListCtrl::SetItem}\label{wxlistctrlsetitem} \func{bool}{SetItem}{\param{wxListItem\& }{info}} @@ -766,6 +835,17 @@ string or image at a given location.} \end{twocollist}} } +\membersection{wxListCtrl::SetItemBackgroundColour}\label{wxlistctrlsetitembackgroundcolour} + +\func{void}{SetItemBackgroundColour}{\param{long }{item}, \param{const wxColour\& }{col}} + +Sets the background colour for this item. This function only works in report view. + +The colour can be retrieved using +\helpref{GetItemBackgroundColour}{wxlistctrlgetitembackgroundcolour}. + + + \membersection{wxListCtrl::SetItemCount}\label{wxlistctrlsetitemcount} \func{void}{SetItemCount}{\param{long }{count}} @@ -776,12 +856,14 @@ program should be ready to handle calls to various item callbacks (such as \helpref{OnGetItemText}{wxlistctrlongetitemtext}) for all items in the range from $0$ to {\it count}. + \membersection{wxListCtrl::SetItemData}\label{wxlistctrlsetitemdata} \func{bool}{SetItemData}{\param{long }{item}, \param{long }{data}} Associates application-defined data with this item. + \membersection{wxListCtrl::SetItemImage}\label{wxlistctrlsetitemimage} \func{bool}{SetItemImage}{\param{long }{item}, \param{int }{image}, \param{int }{selImage}} @@ -789,12 +871,14 @@ Associates application-defined data with this item. Sets the unselected and selected images associated with the item. The images are indices into the image list associated with the list control. + \membersection{wxListCtrl::SetItemPosition}\label{wxlistctrlsetitemposition} \func{bool}{SetItemPosition}{\param{long }{item}, \param{const wxPoint\& }{pos}} Sets the position of the item, in icon or small icon view. + \membersection{wxListCtrl::SetItemState}\label{wxlistctrlsetitemstate} \func{bool}{SetItemState}{\param{long }{item}, \param{long }{state}, \param{long }{stateMask}} @@ -803,30 +887,45 @@ Sets the item state. For a list of state flags, see \helpref{wxListCtrl::SetItem The {\bf stateMask} indicates which state flags are valid. + \membersection{wxListCtrl::SetItemText}\label{wxlistctrlsetitemtext} \func{void}{SetItemText}{\param{long }{item}, \param{const wxString\& }{text}} Sets the item text for this item. + +\membersection{wxListCtrl::SetItemTextColour}\label{wxlistctrlsetitemtextcolour} + +\func{void}{SetItemTextColour}{\param{long }{item}, \param{const wxColour\& }{col}} + +Sets the colour for this item. This function only works in report view. + +The colour can be retrieved using +\helpref{GetItemTextColour}{wxlistctrlgetitemtextcolour}. + + \membersection{wxListCtrl::SetSingleStyle}\label{wxlistctrlsetsinglestyle} \func{void}{SetSingleStyle}{\param{long }{style}, \param{const bool }{add = true}} Adds or removes a single window style. + \membersection{wxListCtrl::SetTextColour}\label{wxlistctrlsettextcolour} \func{void}{SetTextColour}{\param{const wxColour\& }{col}} Sets the text colour of the list control. + \membersection{wxListCtrl::SetWindowStyleFlag}\label{wxlistctrlsetwindowstyleflag} \func{void}{SetWindowStyleFlag}{\param{long }{style}} Sets the whole window style. + \membersection{wxListCtrl::SortItems}\label{wxlistctrlsortitems} \func{bool}{SortItems}{\param{wxListCtrlCompare }{fnSortCallBack}, \param{long }{data}} diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 9bb556cf46..c3193b7198 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -206,7 +206,7 @@ public: // Get the internal data structure static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId); -static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId); +static wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId); static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId); static void wxDeleteInternalData(wxListCtrl* ctl, long itemId); @@ -329,7 +329,6 @@ void wxListCtrl::Init() m_imageListSmall = NULL; m_imageListState = NULL; m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; - m_baseStyle = 0; m_colCount = 0; m_count = 0; m_ignoreChangeMessages = FALSE; @@ -343,108 +342,117 @@ bool wxListCtrl::Create(wxWindow *parent, const wxPoint& pos, const wxSize& size, long style, - const wxValidator& wxVALIDATOR_PARAM(validator), + const wxValidator& validator, const wxString& name) { -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif // wxUSE_VALIDATORS + if ( !CreateControl(parent, id, pos, size, style, validator, name) ) + return FALSE; - SetName(name); + if ( !MSWCreateControl(WC_LISTVIEW, _T(""), pos, size) ) + return FALSE; - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; + // explicitly say that we want to use Unicode because otherwise we get ANSI + // versions of _some_ messages (notably LVN_GETDISPINFOA) in MSLU build +#if wxUSE_UNICODE + ::SendMessage(GetHwnd(), LVM_SETUNICODEFORMAT, TRUE, 0); +#endif - m_windowStyle = style; + // for comctl32.dll v 4.70+ we want to have this attribute because it's + // prettier (and also because wxGTK does it like this) + if ( HasFlag(wxLC_REPORT) && wxTheApp->GetComCtl32Version() >= 470 ) + { + ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE, + 0, LVS_EX_FULLROWSELECT); + } - SetParent(parent); + // inherit foreground colour but our background should be the same as for + // listboxes and other such "container" windows and not inherited + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + SetForegroundColour(GetParent()->GetForegroundColour()); - if (width <= 0) - width = 100; - if (height <= 0) - height = 30; - if (x < 0) - x = 0; - if (y < 0) - y = 0; + return TRUE; +} - m_windowId = (id == -1) ? NewControlId() : id; +WXDWORD wxListCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const +{ + WXDWORD wstyle = wxControl::MSWGetStyle(style, exstyle); - DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | - LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; + wstyle |= LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; - m_baseStyle = wstyle; +#ifdef __WXDEBUG__ + size_t nModes = 0; - if ( !DoCreateControl(x, y, width, height) ) - return FALSE; + #define MAP_MODE_STYLE(wx, ms) \ + if ( style & (wx) ) { wstyle |= (ms); nModes++; } +#else // !__WXDEBUG__ + #define MAP_MODE_STYLE(wx, ms) \ + if ( style & (wx) ) wstyle |= (ms); +#endif // __WXDEBUG__ - if (parent) - parent->AddChild(this); + MAP_MODE_STYLE(wxLC_ICON, LVS_ICON) + MAP_MODE_STYLE(wxLC_SMALL_ICON, LVS_SMALLICON) + MAP_MODE_STYLE(wxLC_LIST, LVS_LIST) + MAP_MODE_STYLE(wxLC_REPORT, LVS_REPORT) - return TRUE; -} + wxASSERT_MSG( nModes == 1, + _T("wxListCtrl style should have exactly one mode bit set") ); -bool wxListCtrl::DoCreateControl(int x, int y, int w, int h) -{ - DWORD wstyle = m_baseStyle; +#undef MAP_MODE_STYLE - WXDWORD exStyle = 0; - WXDWORD standardStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; + if ( style & wxLC_ALIGN_LEFT ) + wstyle |= LVS_ALIGNLEFT; - long oldStyle = 0; // Dummy - wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle); - wstyle |= standardStyle; + if ( style & wxLC_ALIGN_TOP ) + wstyle |= LVS_ALIGNTOP; - // Create the ListView control. - m_hWnd = (WXHWND)CreateWindowEx(exStyle, - WC_LISTVIEW, - wxEmptyString, - wstyle, - x, y, w, h, - GetWinHwnd(GetParent()), - (HMENU)m_windowId, - wxGetInstance(), - NULL); + if ( style & wxLC_AUTOARRANGE ) + wstyle |= LVS_AUTOARRANGE; - if ( !m_hWnd ) - { - wxLogError(_("Can't create list control window, check that comctl32.dll is installed.")); + if ( style & wxLC_NO_SORT_HEADER ) + wstyle |= LVS_NOSORTHEADER; - return FALSE; - } + if ( style & wxLC_NO_HEADER ) + wstyle |= LVS_NOCOLUMNHEADER; - // explicitly say that we want to use Unicode because otherwise we get ANSI - // versions of _some_ messages (notably LVN_GETDISPINFOA) in MSLU build -#if wxUSE_UNICODE - ::SendMessage(GetHwnd(), LVM_SETUNICODEFORMAT, TRUE, 0); -#endif + if ( style & wxLC_EDIT_LABELS ) + wstyle |= LVS_EDITLABELS; - // for comctl32.dll v 4.70+ we want to have this attribute because it's - // prettier (and also because wxGTK does it like this) - if ( (wstyle & LVS_REPORT) && wxTheApp->GetComCtl32Version() >= 470 ) + if ( style & wxLC_SINGLE_SEL ) + wstyle |= LVS_SINGLESEL; + + if ( style & wxLC_SORT_ASCENDING ) { - ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE, - 0, LVS_EX_FULLROWSELECT); + wstyle |= LVS_SORTASCENDING; + + wxASSERT_MSG( !(style & wxLC_SORT_DESCENDING), + _T("can't sort in ascending and descending orders at once") ); } + else if ( style & wxLC_SORT_DESCENDING ) + wstyle |= LVS_SORTDESCENDING; - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(GetParent()->GetForegroundColour()); +#if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) + if ( style & wxLC_VIRTUAL ) + { + int ver = wxTheApp->GetComCtl32Version(); + if ( ver < 470 ) + { + wxLogWarning(_("Please install a newer version of comctl32.dll\n(at least version 4.70 is required but you have %d.%02d)\nor this program won't operate correctly."), + ver / 100, ver % 100); + } - SubclassWin(m_hWnd); + wstyle |= LVS_OWNERDATA; + } +#endif // ancient cygwin - return TRUE; + return wstyle; } void wxListCtrl::UpdateStyle() { - if ( GetHWND() ) + if ( GetHwnd() ) { // The new window view style - long dummy; - DWORD dwStyleNew = ConvertToMSWStyle(dummy, m_windowStyle); - dwStyleNew |= m_baseStyle; + DWORD dwStyleNew = MSWGetStyle(m_windowStyle, NULL); // Get the current window style. DWORD dwStyleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE); @@ -536,115 +544,6 @@ void wxListCtrl::SetWindowStyleFlag(long flag) UpdateStyle(); } -// Can be just a single style, or a bitlist -long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const -{ - long wstyle = 0; - if ( style & wxLC_ICON ) - { - if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) - oldStyle -= LVS_SMALLICON; - if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) - oldStyle -= LVS_REPORT; - if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) - oldStyle -= LVS_LIST; - wstyle |= LVS_ICON; - } - - if ( style & wxLC_SMALL_ICON ) - { - if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) - oldStyle -= LVS_ICON; - if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) - oldStyle -= LVS_REPORT; - if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) - oldStyle -= LVS_LIST; - wstyle |= LVS_SMALLICON; - } - - if ( style & wxLC_LIST ) - { - if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) - oldStyle -= LVS_ICON; - if ( (oldStyle & LVS_TYPEMASK) == LVS_REPORT ) - oldStyle -= LVS_REPORT; - if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) - oldStyle -= LVS_SMALLICON; - wstyle |= LVS_LIST; - } - - if ( style & wxLC_REPORT ) - { - if ( (oldStyle & LVS_TYPEMASK) == LVS_ICON ) - oldStyle -= LVS_ICON; - if ( (oldStyle & LVS_TYPEMASK) == LVS_LIST ) - oldStyle -= LVS_LIST; - if ( (oldStyle & LVS_TYPEMASK) == LVS_SMALLICON ) - oldStyle -= LVS_SMALLICON; - - wstyle |= LVS_REPORT; - } - - if ( style & wxLC_ALIGN_LEFT ) - { - if ( oldStyle & LVS_ALIGNTOP ) - oldStyle -= LVS_ALIGNTOP; - wstyle |= LVS_ALIGNLEFT; - } - - if ( style & wxLC_ALIGN_TOP ) - { - if ( oldStyle & LVS_ALIGNLEFT ) - oldStyle -= LVS_ALIGNLEFT; - wstyle |= LVS_ALIGNTOP; - } - - if ( style & wxLC_AUTOARRANGE ) - wstyle |= LVS_AUTOARRANGE; - - if ( style & wxLC_NO_SORT_HEADER ) - wstyle |= LVS_NOSORTHEADER; - - if ( style & wxLC_NO_HEADER ) - wstyle |= LVS_NOCOLUMNHEADER; - - if ( style & wxLC_EDIT_LABELS ) - wstyle |= LVS_EDITLABELS; - - if ( style & wxLC_SINGLE_SEL ) - wstyle |= LVS_SINGLESEL; - - if ( style & wxLC_SORT_ASCENDING ) - { - if ( oldStyle & LVS_SORTDESCENDING ) - oldStyle -= LVS_SORTDESCENDING; - wstyle |= LVS_SORTASCENDING; - } - - if ( style & wxLC_SORT_DESCENDING ) - { - if ( oldStyle & LVS_SORTASCENDING ) - oldStyle -= LVS_SORTASCENDING; - wstyle |= LVS_SORTDESCENDING; - } - -#if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) - if ( style & wxLC_VIRTUAL ) - { - int ver = wxTheApp->GetComCtl32Version(); - if ( ver < 470 ) - { - wxLogWarning(_("Please install a newer version of comctl32.dll\n(at least version 4.70 is required but you have %d.%02d)\nor this program won't operate correctly."), - ver / 100, ver % 100); - } - - wstyle |= LVS_OWNERDATA; - } -#endif - - return wstyle; -} - // ---------------------------------------------------------------------------- // accessors // ---------------------------------------------------------------------------- @@ -1150,10 +1049,12 @@ void wxListCtrl::SetItemTextColour( long item, const wxColour &col ) wxColour wxListCtrl::GetItemTextColour( long item ) const { - wxListItem info; - info.m_itemId = item; - GetItem( info ); - return info.GetTextColour(); + wxColour col; + wxListItemInternalData *data = wxGetInternalData(this, item); + if ( data && data->attr ) + col = data->attr->GetTextColour(); + + return col; } void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) @@ -1166,10 +1067,12 @@ void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) wxColour wxListCtrl::GetItemBackgroundColour( long item ) const { - wxListItem info; - info.m_itemId = item; - GetItem( info ); - return info.GetBackgroundColour(); + wxColour col; + wxListItemInternalData *data = wxGetInternalData(this, item); + if ( data && data->attr ) + col = data->attr->GetBackgroundColour(); + + return col; } // Gets the number of selected items in the list control @@ -2525,31 +2428,33 @@ void wxListCtrl::RefreshItems(long itemFrom, long itemTo) RefreshRect(rect); } +// ---------------------------------------------------------------------------- +// internal data stuff +// ---------------------------------------------------------------------------- + static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId) { LV_ITEM it; it.mask = LVIF_PARAM; it.iItem = itemId; - bool success = ListView_GetItem(hwnd, &it) != 0; - if (success) - return (wxListItemInternalData *) it.lParam; - else + if ( !ListView_GetItem(hwnd, &it) ) return NULL; + + return (wxListItemInternalData *) it.lParam; }; -static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId) +static +wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId) { - return wxGetInternalData((HWND) ctl->GetHWND(), itemId); + return wxGetInternalData(GetHwndOf(ctl), itemId); }; static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId) { wxListItemInternalData *data = wxGetInternalData(ctl, itemId); - if (data) - return data->attr; - else - return NULL; + + return data ? data->attr : NULL; }; static void wxDeleteInternalData(wxListCtrl* ctl, long itemId) @@ -2567,6 +2472,10 @@ static void wxDeleteInternalData(wxListCtrl* ctl, long itemId) } } +// ---------------------------------------------------------------------------- +// wxWin <-> MSW items conversions +// ---------------------------------------------------------------------------- + static void wxConvertFromMSWListItem(HWND hwndListCtrl, wxListItem& info, LV_ITEM& lvItem) -- 2.45.2