]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/listctrl.cpp
Don't skip after writing tab or we could get another one in some circumstances
[wxWidgets.git] / src / msw / listctrl.cpp
index baf227794a16bac4230b22ff85b4020579d6d9dc..a8316267c2b64b42c9f02736a773dfbbfe4276cd 100644 (file)
 // include <commctrl.h> "properly"
 #include "wx/msw/wrapcctl.h"
 
+// Currently gcc and watcom don't define NMLVFINDITEM, and DMC only defines
+// it by its old name NM_FINDTIEM.
+//
+#if defined(__VISUALC__) || defined(__BORLANDC__) || defined(NMLVFINDITEM)
+    #define HAVE_NMLVFINDITEM 1
+#elif defined(__DMC__) || defined(NM_FINDITEM)
+    #define HAVE_NMLVFINDITEM 1
+    #define NMLVFINDITEM NM_FINDITEM
+#endif
+
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
@@ -1083,6 +1093,24 @@ wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
     return col;
 }
 
+void wxListCtrl::SetItemFont( long item, const wxFont &f )
+{
+    wxListItem info;
+    info.m_itemId = item;
+    info.SetFont( f );
+    SetItem( info );
+}
+
+wxFont wxListCtrl::GetItemFont( long item ) const
+{
+    wxFont f;
+    wxListItemInternalData *data = wxGetInternalData(this, item);
+    if ( data && data->attr )
+        f = data->attr->GetFont();
+
+    return f;
+}
+
 // Gets the number of selected items in the list control
 int wxListCtrl::GetSelectedItemCount() const
 {
@@ -1834,7 +1862,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
                 event.m_item.m_data = internaldata->lParam;
         }
 
-
+        bool processed = true;
         switch ( nmhdr->code )
         {
             case LVN_BEGINRDRAG:
@@ -2133,6 +2161,78 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
                 }
                 break;
 
+#ifdef HAVE_NMLVFINDITEM
+            case LVN_ODFINDITEM:
+                // this message is only used with the virtual list control but
+                // even there we don't want to always use it: in a control with
+                // sufficiently big number of items (defined as > 1000 here),
+                // accidentally pressing a key could result in hanging an
+                // application waiting while it performs linear search
+                if ( IsVirtual() && GetItemCount() <= 1000 )
+                {
+                    NMLVFINDITEM* pFindInfo = (NMLVFINDITEM*)lParam;
+
+                    // no match by default
+                    *result = -1;
+
+                    // we only handle string-based searches here
+                    //
+                    // TODO: what about LVFI_PARTIAL, should we handle this?
+                    if ( !(pFindInfo->lvfi.flags & LVFI_STRING) )
+                    {
+                        return false;
+                    }
+
+                    const wxChar * const searchstr = pFindInfo->lvfi.psz;
+                    const size_t len = wxStrlen(searchstr);
+
+                    // this is the first item we should examine, search from it
+                    // wrapping if necessary
+                    const int startPos = pFindInfo->iStart;
+                    const int maxPos = GetItemCount();
+                    wxCHECK_MSG( startPos <= maxPos, false,
+                                 _T("bad starting position in LVN_ODFINDITEM") );
+
+                    int currentPos = startPos;
+                    do
+                    {
+                        // wrap to the beginning if necessary
+                        if ( currentPos == maxPos )
+                        {
+                            // somewhat surprizingly, LVFI_WRAP isn't set in
+                            // flags but we still should wrap
+                            currentPos = 0;
+                        }
+
+                        // does this item begin with searchstr?
+                        if ( wxStrnicmp(searchstr,
+                                            GetItemText(currentPos), len) == 0 )
+                        {
+                            *result = currentPos;
+                            break;
+                        }
+                    }
+                    while ( ++currentPos != startPos );
+
+                    if ( *result == -1 )
+                    {
+                        // not found
+                        return false;
+                    }
+
+                    SetItemState(*result,
+                                 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
+                                 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
+                    EnsureVisible(*result);
+                    return true;
+                }
+                else
+                {
+                    processed = false;
+                }
+                break;
+#endif // HAVE_NMLVFINDITEM
+
             case LVN_GETDISPINFO:
                 if ( IsVirtual() )
                 {
@@ -2165,8 +2265,11 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
                 // fall through
 
             default:
-                return wxControl::MSWOnNotify(idCtrl, lParam, result);
+                processed = false;
         }
+
+        if ( !processed )
+            return wxControl::MSWOnNotify(idCtrl, lParam, result);
     }
     else
     {
@@ -2202,7 +2305,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
 
         case LVN_ENDLABELEDITA:
         case LVN_ENDLABELEDITW:
-            // logic here is inversed compared to all the other messages
+            // logic here is inverted compared to all the other messages
             *result = event.IsAllowed();
 
             // don't keep a stale wxTextCtrl around
@@ -2722,7 +2825,8 @@ static void wxConvertToMSWListCol(int WXUNUSED(col), const wxListItem& item,
             //
             // we don't use LVCFMT_COL_HAS_IMAGES because it doesn't seem to
             // make any difference in my tests -- but maybe we should?
-            lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT | LVCFMT_IMAGE;
+            if ( item.m_image != -1 )
+                lvCol.fmt |= LVCFMT_BITMAP_ON_RIGHT | LVCFMT_IMAGE;
 
             lvCol.iImage = item.m_image;
         }