foobar2000 SDK  2015-08-03
Static Public Member Functions
TypeFind

#include <win32_misc.h>

Static Public Member Functions

static size_t _ItemCount (HWND wnd)
 
static const wchar_t * _ItemText (HWND wnd, size_t index, int subItem=0)
 
static LRESULT Handler (NMHDR *hdr, int subItemFrom=0, int subItemCnt=1)
 
static wchar_t myCharLower (wchar_t c)
 
static bool StringPartialMatch (const wchar_t *part, const wchar_t *str)
 
static bool StringPrefixMatch (const wchar_t *part, const wchar_t *str)
 

Detailed Description

Definition at line 212 of file win32_misc.h.

Member Function Documentation

static size_t TypeFind::_ItemCount ( HWND  wnd)
inlinestatic

Definition at line 265 of file win32_misc.h.

265  {
266  return ListView_GetItemCount(wnd);
267  }
static const wchar_t* TypeFind::_ItemText ( HWND  wnd,
size_t  index,
int  subItem = 0 
)
inlinestatic

Definition at line 268 of file win32_misc.h.

268  {
269  NMLVDISPINFO info = {};
270  info.hdr.code = LVN_GETDISPINFO;
271  info.hdr.idFrom = GetDlgCtrlID(wnd);
272  info.hdr.hwndFrom = wnd;
273  info.item.iItem = index;
274  info.item.iSubItem = subItem;
275  info.item.mask = LVIF_TEXT;
276  ::SendMessage(::GetParent(wnd), WM_NOTIFY, info.hdr.idFrom, reinterpret_cast<LPARAM>(&info));
277  if (info.item.pszText == NULL) return L"";
278  return info.item.pszText;
279  }
void info(const char *p_message)
Definition: console.cpp:4
static LRESULT TypeFind::Handler ( NMHDR *  hdr,
int  subItemFrom = 0,
int  subItemCnt = 1 
)
inlinestatic

Definition at line 214 of file win32_misc.h.

214  {
215  NMLVFINDITEM * info = reinterpret_cast<NMLVFINDITEM*>(hdr);
216  const HWND wnd = hdr->hwndFrom;
217  if (info->lvfi.flags & LVFI_NEARESTXY) return -1;
218  const size_t count = _ItemCount(wnd);
219  if (count == 0) return -1;
220  const size_t base = (size_t) info->iStart % count;
221  for(size_t walk = 0; walk < count; ++walk) {
222  const size_t index = (walk + base) % count;
223  for(int subItem = subItemFrom; subItem < subItemFrom + subItemCnt; ++subItem) {
224  if (StringPrefixMatch(info->lvfi.psz, _ItemText(wnd, index, subItem))) return (LRESULT) index;
225  }
226  }
227  for(size_t walk = 0; walk < count; ++walk) {
228  const size_t index = (walk + base) % count;
229  for(int subItem = subItemFrom; subItem < subItemFrom + subItemCnt; ++subItem) {
230  if (StringPartialMatch(info->lvfi.psz, _ItemText(wnd, index, subItem))) return (LRESULT) index;
231  }
232  }
233  return -1;
234  }
void info(const char *p_message)
Definition: console.cpp:4
static bool StringPartialMatch(const wchar_t *part, const wchar_t *str)
Definition: win32_misc.h:250
static bool StringPrefixMatch(const wchar_t *part, const wchar_t *str)
Definition: win32_misc.h:239
static size_t _ItemCount(HWND wnd)
Definition: win32_misc.h:265
static const wchar_t * _ItemText(HWND wnd, size_t index, int subItem=0)
Definition: win32_misc.h:268
static wchar_t TypeFind::myCharLower ( wchar_t  c)
inlinestatic

Definition at line 236 of file win32_misc.h.

236  {
237  return (wchar_t) CharLower((wchar_t*)c);
238  }
static bool TypeFind::StringPartialMatch ( const wchar_t *  part,
const wchar_t *  str 
)
inlinestatic

Definition at line 250 of file win32_misc.h.

250  {
251  unsigned base = 0;
252  for(;;) {
253  unsigned walk = 0;
254  for(;;) {
255  wchar_t c1 = part[walk], c2 = str[base + walk];
256  if (c1 == 0) return true;
257  if (c2 == 0) return false;
258  if (myCharLower(c1) != myCharLower(c2)) break;
259  ++walk;
260  }
261  ++ base;
262  }
263  }
static wchar_t myCharLower(wchar_t c)
Definition: win32_misc.h:236
static bool TypeFind::StringPrefixMatch ( const wchar_t *  part,
const wchar_t *  str 
)
inlinestatic

Definition at line 239 of file win32_misc.h.

239  {
240  unsigned walk = 0;
241  for(;;) {
242  wchar_t c1 = part[walk], c2 = str[walk];
243  if (c1 == 0) return true;
244  if (c2 == 0) return false;
245  if (myCharLower(c1) != myCharLower(c2)) return false;
246  ++walk;
247  }
248  }
static wchar_t myCharLower(wchar_t c)
Definition: win32_misc.h:236

The documentation for this class was generated from the following file: