@@ -288,9 +288,50 @@ int GenericListControl::HandleNotify(LPARAM lParam) {
288
288
return 0 ;
289
289
}
290
290
291
+ if (mhdr->code == LVN_INCREMENTALSEARCH) {
292
+ NMLVFINDITEM *request = (NMLVFINDITEM *)lParam;
293
+ uint32_t supported = LVFI_WRAP | LVFI_STRING | LVFI_PARTIAL | LVFI_SUBSTRING;
294
+ if ((request->lvfi .flags & ~supported) == 0 && (request->lvfi .flags & LVFI_STRING) != 0 ) {
295
+ bool wrap = (request->lvfi .flags & LVFI_WRAP) != 0 ;
296
+ bool partial = (request->lvfi .flags & (LVFI_PARTIAL | LVFI_SUBSTRING)) != 0 ;
297
+
298
+ // It seems like 0 is always sent for start, let's override.
299
+ int startRow = request->iStart ;
300
+ if (startRow == 0 )
301
+ startRow = GetSelectedIndex ();
302
+ int result = OnIncrementalSearch (startRow, request->lvfi .psz , wrap, partial);
303
+ if (result != -1 ) {
304
+ request->lvfi .flags = LVFI_PARAM;
305
+ request->lvfi .lParam = (LPARAM)result;
306
+ }
307
+ }
308
+ }
309
+
291
310
return 0 ;
292
311
}
293
312
313
+ int GenericListControl::OnIncrementalSearch (int startRow, const wchar_t *str, bool wrap, bool partial) {
314
+ return -1 ;
315
+ int size = GetRowCount ();
316
+ size_t searchlen = wcslen (str);
317
+ if (!wrap)
318
+ size -= startRow;
319
+
320
+ // We start with the earliest column, preferring matches on the leftmost columns by default.
321
+ for (int c = 0 ; c < columnCount; ++c) {
322
+ for (int i = 0 ; i < size; ++i) {
323
+ int r = (startRow + i) % size;
324
+ stringBuffer[0 ] = 0 ;
325
+ GetColumnText (stringBuffer, r, c);
326
+ int difference = partial ? _wcsnicmp (str, stringBuffer, searchlen) : _wcsicmp (str, stringBuffer);
327
+ if (difference == 0 )
328
+ return r;
329
+ }
330
+ }
331
+
332
+ return -1 ;
333
+ }
334
+
294
335
void GenericListControl::Update () {
295
336
if (!updateScheduled_) {
296
337
SetTimer (handle, IDT_UPDATE, UPDATE_DELAY, nullptr );
0 commit comments