int AutoCompData::FindPartialWord( const wxString& word, const wxArrayString& array ) { // Do a simple binary search as we know the list // is sorted... this should be super quick. const size_t len = word.Length(); size_t i, lo = 0, hi = array.GetCount(); int res; while ( lo < hi ) { i = (lo + hi) / 2; wxASSERT( array[i] ); res = wxStrnicmp( word, array[i], len ); if ( res < 0 ) hi = i; else if ( res > 0 ) lo = i + 1; else return i; } return wxNOT_FOUND; }
int AutoCompData::FindString( const wxChar* word, const wxChar* words, const wxArrayInt& indicies ) { // Do a simple binary search using the index array // to find the strings in the word list. It's all // sorted, so it should be super quick. size_t i, lo = 0, hi = indicies.GetCount(); int res; const wxChar* other; size_t wordLen = wxStrlen( word ); while ( lo < hi ) { i = (lo + hi) / 2; other = words + indicies[i]; res = wxStrnicmp(word, other, wordLen); if ( res < 0 ) hi = i; else if ( res > 0 ) lo = i + 1; else return i; } return -1; }
bool wxListBox::FindItem(const wxString& prefix, bool strictlyAfter) { int count = GetCount(); if ( !count ) { // empty listbox, we can't find anything in it return false; } // start either from the current item or from the next one if strictlyAfter // is true int first; if ( strictlyAfter ) { // the following line will set first correctly to 0 if there is no // selection (m_current == -1) first = m_current == count - 1 ? 0 : m_current + 1; } else // start with the current { first = m_current == -1 ? 0 : m_current; } int last = first == 0 ? count - 1 : first - 1; // if this is not true we'd never exit from the loop below! wxASSERT_MSG( first < count && last < count, _T("logic error") ); // precompute it outside the loop size_t len = prefix.length(); // loop over all items in the listbox for ( int item = first; item != last; item < count - 1 ? item++ : item = 0 ) { if ( wxStrnicmp(this->GetString(item).c_str(), prefix, len) == 0 ) { SetCurrentItem(item); if ( !(GetWindowStyle() & wxLB_MULTIPLE) ) { DeselectAll(item); SelectAndNotify(item); if ( GetWindowStyle() & wxLB_EXTENDED ) AnchorSelection(item); } return true; } } // nothing found return false; }
void SymbolTree::SelectItemByName(const wxString &name) { std::map<wxString, void*>::iterator iter = m_items.begin(); for (; iter != m_items.end(); iter++) { wxString tmpkey = iter->first; wxString key(tmpkey); // tmpkey.StartsWith(wxT("[prototype] "), &key); wxString path = key.BeforeFirst(wxT('(')); //get the name from the path path = path.AfterLast(wxT(':')); if (wxStrnicmp(path, name, name.Length()) == 0) { //we got an item to select SelectItem(iter->second); return; } } }
wxFontFamily wxNativeFontInfo::GetFamily() const { wxFontFamily ret = wxFONTFAMILY_UNKNOWN; const char *family_name = pango_font_description_get_family( description ); // note: not passing -1 as the 2nd parameter to g_ascii_strdown to work // around a bug in the 64-bit glib shipped with solaris 10, -1 causes it // to try to allocate 2^32 bytes. if ( !family_name ) return ret; wxGtkString family_text(g_ascii_strdown(family_name, strlen(family_name))); // Check for some common fonts, to salvage what we can from the current // win32 centric wxFont API: if (wxStrnicmp( family_text, "monospace", 9 ) == 0) ret = wxFONTFAMILY_TELETYPE; // begins with "Monospace" else if (wxStrnicmp( family_text, "courier", 7 ) == 0) ret = wxFONTFAMILY_TELETYPE; // begins with "Courier" #if defined(__WXGTK20__) || defined(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE) else { PangoFontFamily **families; PangoFontFamily *family = NULL; int n_families; PangoContext* context = wxGetPangoContext(); pango_context_list_families(context, &families, &n_families); for (int i = 0; i < n_families; ++i) { if (g_ascii_strcasecmp(pango_font_family_get_name( families[i] ), pango_font_description_get_family( description )) == 0 ) { family = families[i]; break; } } g_free(families); g_object_unref(context); // Some gtk+ systems might query for a non-existing font from // wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) on initialization, // don't assert until wxSystemSettings::GetFont is checked for this - MR // wxASSERT_MSG( family, "No appropriate PangoFontFamily found for ::description" ); if (family != NULL && pango_font_family_is_monospace( family )) ret = wxFONTFAMILY_TELETYPE; // is deemed a monospace font by pango } #endif // GTK+ 2 || HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE if (ret == wxFONTFAMILY_UNKNOWN) { if (strstr( family_text, "sans" ) != NULL || strstr( family_text, "Sans" ) != NULL) // checked before serif, so that "* Sans Serif" fonts are detected correctly ret = wxFONTFAMILY_SWISS; // contains "Sans" else if (strstr( family_text, "serif" ) != NULL || strstr( family_text, "Serif" ) != NULL) ret = wxFONTFAMILY_ROMAN; // contains "Serif" else if (wxStrnicmp( family_text, "times", 5 ) == 0) ret = wxFONTFAMILY_ROMAN; // begins with "Times" else if (wxStrnicmp( family_text, "old", 3 ) == 0) ret = wxFONTFAMILY_DECORATIVE; // begins with "Old" - "Old English", "Old Town" } return ret; }
bool CLocalPath::SetPath(const wxString& path, wxString* file /*=0*/) { // This function ensures that the path is in canonical form on success. if (path.empty()) { m_path.clear(); return false; } std::deque<wxChar*> segments; // List to store the beginnings of segments const wxChar* in = path.c_str(); { wxStringBuffer start(m_path.get(), path.Len() + 2); wxChar* out = start; #ifdef __WXMSW__ if (path == _T("\\")) { *out++ = '\\'; *out++ = 0; if (file) file->clear(); return true; } if (*in == '\\') { // possibly UNC in++; if (*in++ != '\\') { *start = 0; return false; } if (*in == '?') { // Could be \\?\c:\foo\bar // or \\?\UNC\server\sharee // or something else we do not support. if (*(++in) != '\\') { return false; } in++; if (((*in >= 'a' && *in <= 'z') || (*in >= 'A' || *in <= 'Z')) && *(in+1) == ':') { // It's \\?\c:\foo\bar goto parse_regular; } if (fz::strlen(in) < 5 || wxStrnicmp(in, _T("UNC\\"), 4)) { return false; } in += 4; } *out++ = '\\'; *out++ = '\\'; // UNC path while (*in) { if (*in == '/' || *in == '\\') break; *out++ = *in++; } *out++ = path_separator; if (out - start <= 3) { // not a valid UNC path *start = 0; return false; } segments.push_back(out); } else if ((*in >= 'a' && *in <= 'z') || (*in >= 'A' || *in <= 'Z')) { parse_regular: // Regular path *out++ = *in++; if (*in++ != ':') { *start = 0; return false; } *out++ = ':'; if (*in != '/' && *in != '\\' && *in) { *start = 0; return false; } *out++ = path_separator; segments.push_back(out); } else { *start = 0; return false; } #else if (*in++ != '/') { // SetPath only accepts absolute paths *start = 0; return false; } *out++ = '/'; segments.push_back(out); #endif enum _last { separator, dot, dotdot, segment }; enum _last last = separator; while (*in) { if (*in == '/' #ifdef __WXMSW__ || *in == '\\' #endif ) { in++; if (last == separator) { // /foo//bar is equal to /foo/bar continue; } else if (last == dot) { // /foo/./bar is equal to /foo/bar last = separator; out = segments.back(); continue; } else if (last == dotdot) { last = separator; // Go two segments back if possible if (segments.size() > 1) segments.pop_back(); wxASSERT(!segments.empty()); out = segments.back(); continue; } // Ordinary segment just ended. *out++ = path_separator; segments.push_back(out); last = separator; continue; } else if (*in == '.') { if (last == separator) last = dot; else if (last == dot) last = dotdot; else if (last == dotdot) last = segment; } else last = segment; *out++ = *in++; } if (last == dot) out = segments.back(); else if (last == dotdot) { if (segments.size() > 1) segments.pop_back(); out = segments.back(); } else if (last == segment) { if (file) { *out = 0; out = segments.back(); *file = out; } else *out++ = path_separator; } *out = 0; } return true; }