X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1169a91932273bc84c23ed9dbd0a2da064d59d66..006271980fc91ab2e10024e77b56f98d6bb5a35b:/src/msw/listctrl.cpp diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index afee0618c9..5fc412bb6b 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); @@ -291,7 +291,7 @@ IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h") wxBEGIN_PROPERTIES_TABLE(wxListCtrl) wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) - wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style + wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style wxEND_PROPERTIES_TABLE() wxBEGIN_HANDLERS_TABLE(wxListCtrl) @@ -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,110 @@ 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 + wxSetCCUnicodeFormat(GetHwnd()); - 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 ( InReportView() && wxTheApp->GetComCtl32Version() >= 470 ) + { + ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE, + 0, LVS_EX_FULLROWSELECT); + } - SetParent(parent); + return TRUE; +} - if (width <= 0) - width = 100; - if (height <= 0) - height = 30; - if (x < 0) - x = 0; - if (y < 0) - y = 0; +WXDWORD wxListCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const +{ + WXDWORD wstyle = wxControl::MSWGetStyle(style, exstyle); - m_windowId = (id == -1) ? NewControlId() : id; + wstyle |= LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; - DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | - LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS; +#ifdef __WXDEBUG__ + size_t nModes = 0; - m_baseStyle = wstyle; + #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 ( !DoCreateControl(x, y, width, height) ) - return FALSE; + 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) - if (parent) - parent->AddChild(this); + wxASSERT_MSG( nModes == 1, + _T("wxListCtrl style should have exactly one mode bit set") ); - return TRUE; -} +#undef MAP_MODE_STYLE -bool wxListCtrl::DoCreateControl(int x, int y, int w, int h) -{ - DWORD wstyle = m_baseStyle; + if ( style & wxLC_ALIGN_LEFT ) + wstyle |= LVS_ALIGNLEFT; - WXDWORD exStyle = 0; - WXDWORD standardStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; + if ( style & wxLC_ALIGN_TOP ) + wstyle |= LVS_ALIGNTOP; - long oldStyle = 0; // Dummy - wstyle |= ConvertToMSWStyle(oldStyle, m_windowStyle); - wstyle |= standardStyle; + if ( style & wxLC_AUTOARRANGE ) + wstyle |= LVS_AUTOARRANGE; - // 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_NO_SORT_HEADER ) + wstyle |= LVS_NOSORTHEADER; - if ( !m_hWnd ) - { - wxLogError(_("Can't create list control window, check that comctl32.dll is installed.")); + if ( style & wxLC_NO_HEADER ) + wstyle |= LVS_NOCOLUMNHEADER; - return FALSE; - } + if ( style & wxLC_EDIT_LABELS ) + wstyle |= LVS_EDITLABELS; - // 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_SINGLE_SEL ) + wstyle |= LVS_SINGLESEL; - // 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_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,119 +537,21 @@ 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; - } +// ---------------------------------------------------------------------------- +// accessors +// ---------------------------------------------------------------------------- -#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); - } +/* static */ wxVisualAttributes +wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant) +{ + wxVisualAttributes attrs = GetCompositeControlsDefaultAttributes(variant); - wstyle |= LVS_OWNERDATA; - } -#endif + // common controls have their own default font + attrs.font = wxGetCCDefaultFont(); - return wstyle; + return attrs; } -// ---------------------------------------------------------------------------- -// accessors -// ---------------------------------------------------------------------------- - // Sets the foreground, i.e. text, colour bool wxListCtrl::SetForegroundColour(const wxColour& col) { @@ -1150,10 +1053,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 +1071,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 @@ -1565,6 +1472,9 @@ long wxListCtrl::InsertItem(wxListItem& info) { // take copy of attributes data->attr = new wxListItemAttr(*info.GetAttributes()); + + // and remember that we have some now... + m_hasAnyAttr = TRUE; } }; @@ -1870,7 +1780,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // there's a GPF in Windows. // By returning TRUE here, we avoid further processing // of this strange message. - if ( info->iItem >= GetColumnCount() ) + if ( (unsigned)info->iItem >= (unsigned)GetColumnCount() ) return TRUE; } // fall through @@ -2391,12 +2301,10 @@ void wxListCtrl::OnPaint(wxPaintEvent& event) // Reset the device origin since it may have been set dc.SetDeviceOrigin(0, 0); - bool drawHRules = ((GetWindowStyle() & wxLC_HRULES) != 0); - bool drawVRules = ((GetWindowStyle() & wxLC_VRULES) != 0); + bool drawHRules = HasFlag(wxLC_HRULES); + bool drawVRules = HasFlag(wxLC_VRULES); - if (!drawHRules && !drawVRules) - return; - if ((GetWindowStyle() & wxLC_REPORT) == 0) + if (!InReportView() || !drawHRules && !drawVRules) return; wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); @@ -2522,31 +2430,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) @@ -2564,6 +2474,10 @@ static void wxDeleteInternalData(wxListCtrl* ctl, long itemId) } } +// ---------------------------------------------------------------------------- +// wxWin <-> MSW items conversions +// ---------------------------------------------------------------------------- + static void wxConvertFromMSWListItem(HWND hwndListCtrl, wxListItem& info, LV_ITEM& lvItem) @@ -2702,7 +2616,7 @@ static void wxConvertToMSWListItem(const wxListCtrl *ctrl, if (info.m_mask & wxLIST_MASK_TEXT) { lvItem.mask |= LVIF_TEXT; - if ( ctrl->GetWindowStyleFlag() & wxLC_USER_TEXT ) + if ( ctrl->HasFlag(wxLC_USER_TEXT) ) { lvItem.pszText = LPSTR_TEXTCALLBACK; } @@ -2778,20 +2692,5 @@ static void wxConvertToMSWListCol(int WXUNUSED(col), const wxListItem& item, #endif // _WIN32_IE >= 0x0300 } -wxListView::wxListView() -{ -} - -wxListView::wxListView(wxWindow *parent, - wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString &name) -{ - Create(parent, winid, pos, size, style, validator, name); -} - #endif // wxUSE_LISTCTRL