HighlightLanguage EditorColourSet::AddHighlightLanguage(int lexer, const wxString& name) { if ( lexer <= wxSCI_LEX_NULL || lexer > wxSCI_LEX_LAST // this is a C::B extension to wxscintilla.h || name.IsEmpty() ) { return HL_NONE; } // fix name to be XML compliant wxString newID; size_t pos = 0; while (pos < name.Length()) { wxChar ch = name[pos]; if (wxIsalnum(ch) || ch == _T('_')) newID.Append(ch); // valid character else if (wxIsspace(ch)) newID.Append(_T('_')); // convert spaces to underscores ++pos; } // make sure it's not starting with a number or underscore. // if it is, prepend an 'A' if (wxIsdigit(newID.GetChar(0)) || newID.GetChar(0) == _T('_')) newID.Prepend(_T('A')); if (GetHighlightLanguage(newID) != HL_NONE) return HL_NONE; m_Sets[newID].m_Langs = name; m_Sets[newID].m_Lexers = lexer; return newID; }
void wxTextValidator::OnChar(wxKeyEvent& event) { /* if ( !M_VTEXTDATA ) return; */ if ( m_validatorWindow ) { int keyCode = event.GetKeyCode(); // we don't filter special keys and Delete if ( !(keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode > WXK_START) && ( ((m_validatorStyle & wxFILTER_INCLUDE_CHAR_LIST) && !IsInCharIncludes(wxString((wxChar) keyCode, 1))) || ((m_validatorStyle & wxFILTER_EXCLUDE_CHAR_LIST) && !IsNotInCharExcludes(wxString((wxChar) keyCode, 1))) || ((m_validatorStyle & wxFILTER_ASCII) && !isascii(keyCode)) || ((m_validatorStyle & wxFILTER_ALPHA) && !wxIsalpha(keyCode)) || ((m_validatorStyle & wxFILTER_ALPHANUMERIC) && !wxIsalnum(keyCode)) || ((m_validatorStyle & wxFILTER_NUMERIC) && !wxIsdigit(keyCode) && keyCode != '.' && keyCode != ',' && keyCode != '-') ) ) { if ( !wxValidator::IsSilent() ) wxBell(); // eat message return; } } event.Skip(); }
bool wxFieldMaskData::IsValidInput(wxChar chNewChar) { bool bIsValidInput=FALSE; switch(m_eType) { // These are the input types. case MaskDataTypeDIGIT: bIsValidInput=wxIsdigit(chNewChar) != 0; break; case MaskDataTypeALPHANUMERIC: bIsValidInput=wxIsalnum(chNewChar) != 0; break; case MaskDataTypeALPHABETIC: case MaskDataTypeALPHAETICUPPER: case MaskDataTypeALPHAETICLOWER: bIsValidInput=wxIsalpha(chNewChar) != 0; break; case MaskDataTypeCHARACTER: if((chNewChar >= 32) && (chNewChar <= 126)) bIsValidInput=TRUE; if((chNewChar >= 128) && (chNewChar <= 255)) bIsValidInput = TRUE; break; } return bIsValidInput; }
wxString wxKeyTextCtrl::ToString(int mod, int key) { // wx ignores non-alnum printable chars // actually, wx gives an assertion error, so it's best to filter out // before passing to ToString() bool char_override = key > 32 && key < WXK_START && !wxIsalnum(key); // wx also ignores modifiers (and does not report meta at all) bool mod_override = key == WXK_SHIFT || key == WXK_CONTROL || key == WXK_ALT; wxAcceleratorEntry ae(mod, char_override || mod_override ? WXK_F1 : key); // Note: wx translates unconditionally (2.8.12, 2.9.1)! // So any strings added below must also be translated unconditionally wxString s = ae.ToString(); if (char_override || mod_override) { int l = s.rfind(wxT('-')); if (l == wxString::npos) l = 0; else l++; s.erase(l); switch (key) { case WXK_SHIFT: s.append(_("SHIFT")); break; case WXK_ALT: s.append(_("ALT")); break; case WXK_CONTROL: s.append(_("CTRL")); break; default: s.append((wxChar)key); } } // on Mac, ctrl/meta become xctrl/cmd // on other, meta is ignored #ifndef __WXMAC__ if (mod & wxMOD_META) { s.insert(0, _("Meta-")); } #endif if (s.empty() || (key != wxT('-') && s[s.size() - 1] == wxT('-'))) // bad key combo; probably also generates an assertion in wx return wxEmptyString; return s; }
bool CValidateEmailAddress::wxIsAlphaNumeric(const wxString& val) { int i; for (i = 0; i < (int)val.Length(); i++) { if (!wxIsalnum(val[i])) return FALSE; } return TRUE; }
/*---------------------------------------------------------------------------*/ void wxCreateTableDialog::OnChar(wxKeyEvent& event) { int c = event.GetKeyCode(); if ((!wxIsalnum(c) && c != ('_') && c != (' ') && c != WXK_BACK && c != WXK_DELETE)&& // Ctrl+C Ctrl+V Ctrl+X !(event.ControlDown() && (c == 3 || c == 22 || c == 24))) return; event.Skip(); }
static bool wxIsAlphaNumeric(const wxString& val) { int i; for ( i = 0; i < (int)val.Length(); i++) { if (!wxIsalnum(val[i])) return false; } return true; }
wxString wxAcceleratorEntry::ToString() const { wxString text; int flags = GetFlags(); if ( flags & wxACCEL_ALT ) text += _("Alt+"); if ( flags & wxACCEL_CTRL ) text += _("Ctrl+"); if ( flags & wxACCEL_SHIFT ) text += _("Shift+"); const int code = GetKeyCode(); if ( code >= WXK_F1 && code <= WXK_F12 ) text << _("F") << code - WXK_F1 + 1; else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 ) text << _("KP_") << code - WXK_NUMPAD0; else if ( code >= WXK_SPECIAL1 && code <= WXK_SPECIAL20 ) text << _("SPECIAL") << code - WXK_SPECIAL1 + 1; else // check the named keys { size_t n; for ( n = 0; n < WXSIZEOF(wxKeyNames); n++ ) { const wxKeyName& kn = wxKeyNames[n]; if ( code == kn.code ) { text << wxGetTranslation(kn.name); break; } } if ( n == WXSIZEOF(wxKeyNames) ) { // must be a simple key if ( #if !wxUSE_UNICODE // we can't call wxIsalnum() for non-ASCII characters in ASCII // build as they're only defined for the ASCII range (or EOF) wxIsascii(code) && #endif // ANSI wxIsalnum(code) ) { text << (wxChar)code; } else { wxFAIL_MSG( wxT("unknown keyboard accelerator code") ); } } } return text; }
/* Returns a string which is equal to the string pointed to by p, but up to the point where p contains an character that's not allowed. Allowable characters are letters and numbers, and characters pointed to by the parameter allowedChars. For example, if p points to "abcde-@-_", and allowedChars is "-_", this function returns "abcde-". */ static wxString GetOptionName(const wxChar *p, const wxChar *allowedChars) { wxString argName; while ( *p && (wxIsalnum(*p) || wxStrchr(allowedChars, *p)) ) { argName += *p++; } return argName; }
int Tokenizer::GetFirstTokenPosition(const wxChar* buffer, const size_t bufferLen, const wxChar* target, const size_t targetLen) { int pos = -1; wxChar* p = const_cast<wxChar*>(buffer); const wxChar* endBuffer = buffer + bufferLen; for (;;) { const int ret = KMP_Find(p, target, targetLen); if (ret == -1) break; // check previous char p += ret; if (p > buffer) { const wxChar ch = *(p - 1); if (ch == _T('_') || wxIsalnum(ch)) { p += targetLen; continue; } } // check next char p += targetLen; if (p < endBuffer) { const wxChar ch = *p; if (ch == _T('_') || wxIsalnum(ch)) continue; } // got it pos = p - buffer - targetLen; break; } return pos; }
/* Returns a string which is equal to the string pointed to by p, but up to the point where p contains an character that's not allowed. Allowable characters are letters and numbers, and characters pointed to by the parameter allowedChars. For example, if p points to "abcde-@-_", and allowedChars is "-_", this function returns "abcde-". */ static wxString GetOptionName(wxString::const_iterator p, wxString::const_iterator end, const wxChar *allowedChars) { wxString argName; while ( p != end && (wxIsalnum(*p) || wxStrchr(allowedChars, *p)) ) { argName += *p++; } return argName; }
void UsrGlblMgrEditDialog::Sanitise(wxString& s) { s.Trim().Trim(true); if (s.IsEmpty()) { s = _T("[?empty?]"); return; } for (unsigned int i = 0; i < s.length(); ++i) #if wxCHECK_VERSION(3, 0, 0) s[i] = wxIsalnum(s.GetChar(i)) ? s.GetChar(i) : wxUniChar('_'); #else s[i] = wxIsalnum(s.GetChar(i)) ? s.GetChar(i) : _T('_'); #endif if (s.GetChar(0) == _T('_')) s.Prepend(_T("set")); if (s.GetChar(0) >= _T('0') && s.GetChar(0) <= _T('9')) s.Prepend(_T("set_")); }
/*---------------------------------------------------------------------------*/ bool wxGridColumnsTable::CheckName(const wxString& name, int row) { wxChar c; // Vérification du nom for (size_t i = 0; i < name.Len(); i++) { c = name.GetChar(i); if (!wxIsalnum(c) && c != ('_') && c != (' ')) return false; } // Vérifie que le nom est unique for (size_t i = 0; i < m_Columns.GetCount(); i++) if ((int)i != row) if (m_Columns[i]->GetName().Upper() == name.Upper()) return false; return true; }
// sanitize entry or group name: insert '\\' before any special characters static wxString FilterOutEntryName(const wxString& str) { wxString strResult; strResult.Alloc(str.Len()); for ( const wxChar *pc = str.c_str(); *pc != wxT('\0'); pc++ ) { wxChar c = *pc; // we explicitly allow some of "safe" chars and 8bit ASCII characters // which will probably never have special meaning // NB: note that wxCONFIG_IMMUTABLE_PREFIX and wxCONFIG_PATH_SEPARATOR // should *not* be quoted if ( !wxIsalnum(c) && !wxStrchr(wxT("@_/-!.*%"), c) && ((c & 0x80) == 0) ) strResult += wxT('\\'); strResult += c; } return strResult; }
wxString wxAcceleratorEntry::ToString() const { wxString text; int flags = GetFlags(); if ( flags & wxACCEL_ALT ) text += _("Alt-"); if ( flags & wxACCEL_CTRL ) text += _("Ctrl-"); if ( flags & wxACCEL_SHIFT ) text += _("Shift-"); const int code = GetKeyCode(); if ( wxIsalnum(code) ) text << (wxChar)code; else if ( code >= WXK_F1 && code <= WXK_F12 ) text << _("F") << code - WXK_F1 + 1; else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 ) text << _("KP_") << code - WXK_NUMPAD0; else if ( code >= WXK_SPECIAL1 && code <= WXK_SPECIAL20 ) text << _("SPECIAL") << code - WXK_SPECIAL1 + 1; else // check the named keys { size_t n; for ( n = 0; n < WXSIZEOF(wxKeyNames); n++ ) { const wxKeyName& kn = wxKeyNames[n]; if ( code == kn.code ) { text << wxGetTranslation(kn.name); break; } } wxASSERT_MSG( n != WXSIZEOF(wxKeyNames), wxT("unknown keyboard accelerator code") ); } return text; }
void MyValidator::OnChar(wxKeyEvent& event) { if (m_validatorWindow) { int keyCode = event.GetKeyCode(); // we don't filter special keys and Delete if (!(keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode > WXK_START)) { bool chOk = true; switch (m_type) { case MYVAL_ANY: break; case MYVAL_NUMERIC: chOk = (wxIsdigit(keyCode) != 0); break; case MYVAL_HEX: chOk = (wxIsxdigit(keyCode) != 0); break; case MYVAL_HOST: chOk = (wxIsalnum(keyCode) || (keyCode == _T('.')) || (keyCode == _T('-'))); break; case MYVAL_FILENAME: chOk = (wxFileName::GetForbiddenChars().Find(keyCode) == -1); break; } if (!chOk) { if (!wxValidator::IsSilent()) wxBell(); // eat message return; } } } if (m_ktc) m_ktc->KeyTyped(); event.Skip(); }
void Compiler::MakeValidID() { // basically, make it XML-element compatible // only allow a-z, 0-9 and _ // (it is already lowercase) // any non-conformant character will be removed wxString newID; if (m_ID.IsEmpty()) m_ID = m_Name; size_t pos = 0; while (pos < m_ID.Length()) { wxChar ch = m_ID[pos]; if (wxIsalnum(ch) || ch == _T('_')) // valid character newID.Append(ch); else if (wxIsspace(ch)) // convert spaces to underscores newID.Append(_T('_')); ++pos; } // make sure it's not starting with a number. // if it is, prepend "cb" if (wxIsdigit(newID.GetChar(0))) newID.Prepend(_T("cb")); if (newID.IsEmpty()) // empty? wtf? cbThrow(_T("Can't create a valid compiler ID for ") + m_Name); m_ID = newID.Lower(); // check for unique ID if (!IsUniqueID(m_ID)) cbThrow(_T("Compiler ID already exists for ") + m_Name); m_CompilerIDs.Add(m_ID); }
wxString EvaluationQueue::GetCommand() { wxString retval; m_userLabel = wxEmptyString; if(!m_tokens.IsEmpty()) { retval = m_tokens[0]; wxString userLabel; int colonPos; if((colonPos = retval.find(wxT(":")))!=wxNOT_FOUND) { userLabel = retval.Left(colonPos); userLabel.Trim(true); userLabel.Trim(false); if((wxIsalpha(userLabel[0]))||(userLabel[0]==wxT('\\'))||(userLabel[0]==wxT('_'))) { for(size_t i=0;i<userLabel.Length();i++) { if(userLabel[i]==wxT('\\')) i++; else { if((!wxIsalnum(userLabel[i]))&&(userLabel[i]!='_')) { userLabel = wxEmptyString; break; } } } m_userLabel = userLabel; } }; } return retval; }
bool CUtils::FindString(const wxString& findIn, const wxString& findWhat, bool wholeWord) { wxString remain(findIn); if (wholeWord) { size_t s = findWhat.Length(); while (!remain.IsEmpty()) { int i = remain.Find(findWhat); if (i == wxNOT_FOUND) { break; } if ((i == 0 || !wxIsalnum(remain[i - 1])) && (i + s == remain.Length() || !wxIsalnum(remain[i + s]))) { return true; } remain = remain.Mid(i + 1); } } else if (remain.Find(findWhat) != wxNOT_FOUND) { return true; } return false; }
static CharType *wxDoExpandPath(CharType *buf, const wxString& name) { CharType *d, *s, *nm; CharType lnm[_MAXPATHLEN]; int q; // Some compilers don't like this line. // const CharType trimchars[] = wxT("\n \t"); CharType trimchars[4]; trimchars[0] = wxT('\n'); trimchars[1] = wxT(' '); trimchars[2] = wxT('\t'); trimchars[3] = 0; static const CharType SEP = wxFILE_SEP_PATH; #ifdef __WINDOWS__ //wxUnix2DosFilename(path); #endif buf[0] = wxT('\0'); if (name.empty()) return buf; nm = ::MYcopystring(static_cast<const CharType*>(name.c_str())); // Make a scratch copy CharType *nm_tmp = nm; /* Skip leading whitespace and cr */ while (wxStrchr(trimchars, *nm) != NULL) nm++; /* And strip off trailing whitespace and cr */ s = nm + (q = wxStrlen(nm)) - 1; while (q-- && wxStrchr(trimchars, *s) != NULL) *s = wxT('\0'); s = nm; d = lnm; #ifdef __WINDOWS__ q = FALSE; #else q = nm[0] == wxT('\\') && nm[1] == wxT('~'); #endif /* Expand inline environment variables */ while ((*d++ = *s) != 0) { # ifndef __WINDOWS__ if (*s == wxT('\\')) { if ((*(d - 1) = *++s)!=0) { s++; continue; } else break; } else # endif #ifdef __WINDOWS__ if (*s++ == wxT('$') && (*s == wxT('{') || *s == wxT(')'))) #else if (*s++ == wxT('$')) #endif { CharType *start = d; int braces = (*s == wxT('{') || *s == wxT('(')); CharType *value; while ((*d++ = *s) != 0) if (braces ? (*s == wxT('}') || *s == wxT(')')) : !(wxIsalnum(*s) || *s == wxT('_')) ) break; else s++; *--d = 0; value = wxGetenv(braces ? start + 1 : start); if (value) { for ((d = start - 1); (*d++ = *value++) != 0;) { // Empty } d--; if (braces && *s) s++; } } } /* Expand ~ and ~user */ wxString homepath; nm = lnm; if (nm[0] == wxT('~') && !q) { /* prefix ~ */ if (nm[1] == SEP || nm[1] == 0) { /* ~/filename */ homepath = wxGetUserHome(wxEmptyString); if (!homepath.empty()) { s = (CharType*)(const CharType*)homepath.c_str(); if (*++nm) nm++; } } else { /* ~user/filename */ CharType *nnm; for (s = nm; *s && *s != SEP; s++) { // Empty } int was_sep; /* MATTHEW: Was there a separator, or NULL? */ was_sep = (*s == SEP); nnm = *s ? s + 1 : s; *s = 0; homepath = wxGetUserHome(wxString(nm + 1)); if (homepath.empty()) { if (was_sep) /* replace only if it was there: */ *s = SEP; s = NULL; } else { nm = nnm; s = (CharType*)(const CharType*)homepath.c_str(); } } } d = buf; if (s && *s) { /* MATTHEW: s could be NULL if user '~' didn't exist */ /* Copy home dir */ while (wxT('\0') != (*d++ = *s++)) /* loop */; // Handle root home if (d - 1 > buf && *(d - 2) != SEP) *(d - 1) = SEP; } s = nm; while ((*d++ = *s++) != 0) { // Empty } delete[] nm_tmp; // clean up alloc /* Now clean up the buffer */ return wxRealPath(buf); }
//vfc add bGetValue wxString Tokenizer::DoGetToken(bool bGetValue, bool bTemplate) { if (IsEOF()) return wxEmptyString; if (!SkipWhiteSpace()) return wxEmptyString; if (m_SkipUnwantedTokens && !SkipUnwanted(bGetValue)) return wxEmptyString; // if m_SkipUnwantedTokens is false, we need to handle comments here too if (!m_SkipUnwantedTokens) SkipComment(); int start = m_TokenIndex; wxString m_Str; wxChar c = CurrentChar(); if (c == '_' || wxIsalpha(c)) { // keywords, identifiers, etc. // operator== is cheaper than wxIsalnum, also MoveToNextChar already includes IsEOF while ( ( CurrentChar() == '_' || wxIsalnum(CurrentChar()) ) && MoveToNextChar() ) ; if (IsEOF()) return wxEmptyString; m_Str = m_Buffer.Mid(start, m_TokenIndex - start); m_IsOperator = m_Str.IsSameAs(TokenizerConsts::operator_str); } #ifdef __WXMSW__ // This is a Windows only bug! else if (c == 178 || c == 179 || c == 185) // fetch ?and ? { m_Str = c; MoveToNextChar(); } #endif else if (wxIsdigit(CurrentChar())) { // numbers while (NotEOF() && CharInString(CurrentChar(), _T("0123456789.abcdefABCDEFXxLl"))) MoveToNextChar(); if (IsEOF()) return wxEmptyString; m_Str = m_Buffer.Mid(start, m_TokenIndex - start); m_IsOperator = false; } else if (CurrentChar() == '"' || CurrentChar() == '\'') { // string, char, etc. wxChar match = CurrentChar(); MoveToNextChar(); // skip starting ' or " if (!SkipToChar(match)) return wxEmptyString; MoveToNextChar(); // skip ending ' or " m_Str = m_Buffer.Mid(start, m_TokenIndex - start); } else if (CurrentChar() == ':') { if (NextChar() == ':') { MoveToNextChar(); MoveToNextChar(); m_Str.assign(TokenizerConsts::colon_colon); // this only copies a pointer, but operator= allocates memory and does a memcpy! } else { MoveToNextChar(); m_Str.assign(TokenizerConsts::colon); } } else if (CurrentChar() == '<' && bTemplate) { wxChar match = _T('>'); MoveToNextChar(); if (!SkipToOneOfChars(_T(">\r\n")),false) return wxEmptyString; MoveToNextChar(); wxString tmp = m_Buffer.Mid(start+1,m_TokenIndex-start-2); tmp.Trim(); m_Str = _T("<"); m_Str += tmp; m_Str += _T(">");//m_Buffer.Mid(start, m_TokenIndex - start); } else if (CurrentChar() == '(') { m_IsOperator = false; // skip blocks () [] if (!SkipBlock(CurrentChar())) return wxEmptyString; wxString tmp = m_Buffer.Mid(start, m_TokenIndex - start); // tmp.Replace(_T("\t"), _T(" ")); // replace tabs with spaces // tmp.Replace(_T("\n"), _T(" ")); // replace LF with spaces // tmp.Replace(_T("\r"), _T(" ")); // replace CR with spaces { // this is much faster: size_t i; while((i = tmp.find_first_of(TokenizerConsts::tabcrlf)) != wxString::npos) //tmp[i] = _T(' '); tmp.SetAt(i,_T(' ')); } // fix-up arguments (remove excessive spaces/tabs/newlines) for (unsigned int i = 0; i < tmp.Length() - 1; ++i) { //skip spaces before '=' and ',' if (tmp.GetChar(i) == ' ' && (tmp.GetChar(i + 1) == ',' || tmp.GetChar(i + 1) == '=')) continue; if (tmp.GetChar(i) == '/' && tmp.GetChar(i + 1) == '*') { // skip C comments i += 2; while (i < tmp.Length() - 1) { if (tmp.GetChar(i) == '*' && tmp.GetChar(i + 1) == '/') break; ++i; } if (i >= tmp.Length() - 1 || tmp.GetChar(i + 1) != '/') continue; // we failed... i += 2; } else if (tmp.GetChar(i) == '=') { // skip default assignments ++i; int level = 0; // nesting parenthesis while (i < tmp.Length()) { if (tmp.GetChar(i) == '(') ++level; else if (tmp.GetChar(i) == ')') --level; if ((tmp.GetChar(i) == ',' && level == 0) || (tmp.GetChar(i) == ')' && level < 0)) break; ++i; } if (i < tmp.Length() && tmp.GetChar(i) == ',') --i; continue; // we are done here } if (i < tmp.Length() - 1) { if ((tmp.GetChar(i) == ' ') && (tmp.GetChar(i + 1) == ' ')) continue; // skip excessive spaces // in case of c-style comments "i" might already be tmp.Length() // thus do only add the current char otherwise. // otherwise the following statement: // m_Str << _T(')'); // below would add another closing bracket. m_Str << tmp.GetChar(i); } } m_Str << _T(')'); // add closing parenthesis (see "i < tmp.Length() - 1" in previous "for") // m_Str.Replace(_T(" "), _T(" ")); // replace two-spaces with single-space (introduced if it skipped comments or assignments) // m_Str.Replace(_T("( "), _T("(")); // m_Str.Replace(_T(" )"), _T(")")); //Str.Replace is massive overkill here since it has to allocate one new block per replacement CompactSpaces(m_Str); } else { if (CurrentChar() == '{') ++m_NestLevel; else if (CurrentChar() == '}') --m_NestLevel; m_Str = CurrentChar(); MoveToNextChar(); } if (m_LastWasPreprocessor && !m_Str.IsSameAs(_T("#")) && !m_LastPreprocessor.IsSameAs(_T("#"))) { if (!m_LastPreprocessor.IsSameAs(TokenizerConsts::include_str)) { // except for #include and #if[[n]def], all other preprocessor directives need only // one word exactly after the directive, e.g. #define THIS_WORD SkipToEOL(); } m_LastPreprocessor.Clear(); } if (m_LastWasPreprocessor) m_LastPreprocessor << m_Str; m_LastWasPreprocessor = false; return m_Str; }
bool wxStdListboxInputHandler::HandleKey(wxInputConsumer *consumer, const wxKeyEvent& event, bool pressed) { // we're only interested in the key press events if ( pressed && !event.AltDown() ) { bool isMoveCmd = true; int style = consumer->GetInputWindow()->GetWindowStyle(); wxControlAction action; wxString strArg; int keycode = event.GetKeyCode(); switch ( keycode ) { // movement case WXK_UP: action = wxACTION_LISTBOX_MOVEUP; break; case WXK_DOWN: action = wxACTION_LISTBOX_MOVEDOWN; break; case WXK_PAGEUP: case WXK_PRIOR: action = wxACTION_LISTBOX_PAGEUP; break; case WXK_PAGEDOWN: case WXK_NEXT: action = wxACTION_LISTBOX_PAGEDOWN; break; case WXK_HOME: action = wxACTION_LISTBOX_START; break; case WXK_END: action = wxACTION_LISTBOX_END; break; // selection case WXK_SPACE: if ( style & wxLB_MULTIPLE ) { action = wxACTION_LISTBOX_TOGGLE; isMoveCmd = false; } break; case WXK_RETURN: action = wxACTION_LISTBOX_ACTIVATE; isMoveCmd = false; break; default: if ( (keycode < 255) && wxIsalnum((wxChar)keycode) ) { action = wxACTION_LISTBOX_FIND; strArg = (wxChar)keycode; } } if ( !action.IsEmpty() ) { consumer->PerformAction(action, -1, strArg); if ( isMoveCmd ) { if ( style & wxLB_SINGLE ) { // the current item is always the one selected consumer->PerformAction(wxACTION_LISTBOX_SELECT); } else if ( style & wxLB_EXTENDED ) { if ( event.ShiftDown() ) consumer->PerformAction(wxACTION_LISTBOX_EXTENDSEL); else { // select the item and make it the new selection anchor consumer->PerformAction(wxACTION_LISTBOX_SELECT); consumer->PerformAction(wxACTION_LISTBOX_ANCHOR); } } //else: nothing to do for multiple selection listboxes } return true; } } return wxStdInputHandler::HandleKey(consumer, event, pressed); }
wxString KeyBinder::GetKeyBindingAsText(const Key& key) { wxString res; if (key.flags & wxACCEL_CTRL) { res += "Ctrl+"; } if (key.flags & wxACCEL_SHIFT) { res += "Shift+"; } if (key.flags & wxACCEL_ALT) { res += "Alt+"; } switch (key.code) { // IGNORED KEYS // --------------------------- case WXK_START: case WXK_LBUTTON: case WXK_RBUTTON: case WXK_MBUTTON: case WXK_CLEAR: case WXK_PAUSE: case WXK_NUMLOCK: case WXK_SCROLL : return wxEmptyString; // these must be ABSOLUTELY ignored: they are key modifiers // we won't output any LOG message since these keys could be pressed // for long time while the user choose its preferred keycombination: // this would result into a long long queue of "ignored key" messages // which would be useless even in debug builds... case WXK_SHIFT: case WXK_CONTROL: return wxEmptyString; // FUNCTION KEYS // --------------------------- case WXK_F1: case WXK_F2: case WXK_F3: case WXK_F4: case WXK_F5: case WXK_F6: case WXK_F7: case WXK_F8: case WXK_F9: case WXK_F10: case WXK_F11: case WXK_F12: case WXK_F13: case WXK_F14: case WXK_F15: case WXK_F16: case WXK_F17: case WXK_F18: case WXK_F19: case WXK_F20: case WXK_F21: case WXK_F22: case WXK_F23: case WXK_F24: res << wxT('F') << key.code - WXK_F1 + 1; break; // MISCELLANEOUS KEYS // --------------------------- case WXK_BACK: res << wxT("Back"); break; case WXK_TAB: res << wxT("Tab"); break; case WXK_RETURN: res << wxT("Return"); break; case WXK_ESCAPE: res << wxT("Escape"); break; case WXK_SPACE: res << wxT("Space"); break; case WXK_DELETE: res << wxT("Del"); break; case WXK_MULTIPLY: res << wxT("*"); break; case WXK_ADD: res << wxT("+"); break; case WXK_SEPARATOR: res << wxT("Separator"); break; case WXK_SUBTRACT: res << wxT("-"); break; case WXK_DECIMAL: res << wxT("."); break; case WXK_DIVIDE: res << wxT("/"); break; case WXK_PAGEUP: res << wxT("PageUp"); break; case WXK_PAGEDOWN: res << wxT("PageDown"); break; case WXK_LEFT: res << wxT("Left"); break; case WXK_UP: res << wxT("Up"); break; case WXK_RIGHT: res << wxT("Right"); break; case WXK_DOWN: res << wxT("Down"); break; case WXK_SELECT: res << wxT("Select"); break; case WXK_PRINT: res << wxT("Print"); break; case WXK_EXECUTE: res << wxT("Execute"); break; case WXK_SNAPSHOT: res << wxT("Snapspot"); break; case WXK_INSERT: res << wxT("Insert"); break; case WXK_HELP: res << wxT("Help"); break; case WXK_CANCEL: res << wxT("Cancel"); break; case WXK_MENU: res << wxT("Menu"); break; case WXK_CAPITAL: res << wxT("Capital"); break; case WXK_END: res << wxT("End"); break; case WXK_HOME: res << wxT("Home"); break; // NUMPAD KEYS // --------------------------- case WXK_NUMPAD0: case WXK_NUMPAD1: case WXK_NUMPAD2: case WXK_NUMPAD3: case WXK_NUMPAD4: case WXK_NUMPAD5: case WXK_NUMPAD6: case WXK_NUMPAD7: case WXK_NUMPAD8: case WXK_NUMPAD9: res << key.code - WXK_NUMPAD0; break; case WXK_NUMPAD_SPACE: res << wxT("Space"); break; case WXK_NUMPAD_TAB: res << wxT("Tab"); break; case WXK_NUMPAD_ENTER: res << wxT("Enter"); break; case WXK_NUMPAD_F1: case WXK_NUMPAD_F2: case WXK_NUMPAD_F3: case WXK_NUMPAD_F4: res << wxT("F") << key.code - WXK_NUMPAD_F1; break; case WXK_NUMPAD_LEFT: res << wxT("Keft"); break; case WXK_NUMPAD_UP: res << wxT("Up"); break; case WXK_NUMPAD_RIGHT: res << wxT("Right"); break; case WXK_NUMPAD_DOWN: res << wxT("Down"); break; case WXK_NUMPAD_HOME: res << wxT("Home"); break; case WXK_NUMPAD_PAGEUP: res << wxT("PageUp"); break; case WXK_NUMPAD_PAGEDOWN: res << wxT("PageDown"); break; case WXK_NUMPAD_END: res << wxT("End"); break; case WXK_NUMPAD_BEGIN: res << wxT("Begin"); break; case WXK_NUMPAD_INSERT: res << wxT("Insert"); break; case WXK_NUMPAD_DELETE: res << wxT("Delete"); break; case '=': case WXK_NUMPAD_EQUAL: res << wxT("="); break; case WXK_NUMPAD_MULTIPLY: res << wxT("*"); break; case '+': case WXK_NUMPAD_ADD: res << wxT("+"); break; case WXK_NUMPAD_SEPARATOR: res << wxT("Separator"); break; case WXK_NUMPAD_SUBTRACT: res << wxT("-"); break; case '.': case WXK_NUMPAD_DECIMAL: res << wxT("."); break; case '/': case WXK_NUMPAD_DIVIDE: res << wxT("/"); break; default: // ASCII chars... if (wxIsalnum(key.code) || wxIsgraph(key.code)) { res << (wxChar)key.code; break; } else { // we couldn't create a description for the given keycode... return wxEmptyString; } } return res; }
wxString Tokenizer::DoGetToken() { int start = m_TokenIndex; bool needReplace = false; wxString str; wxChar c = CurrentChar(); if (c == '_' || wxIsalpha(c)) { // keywords, identifiers, etc. // operator== is cheaper than wxIsalnum, also MoveToNextChar already includes IsEOF while ( ( (c == '_') || (wxIsalnum(c)) ) && MoveToNextChar() ) c = CurrentChar(); // repeat if (IsEOF()) return wxEmptyString; needReplace = true; str = m_Buffer.Mid(start, m_TokenIndex - start); } #ifdef __WXMSW__ // This is a Windows only bug! // fetch non-English characters, see more details in: http://forums.codeblocks.org/index.php/topic,11387.0.html else if (c == 178 || c == 179 || c == 185) { str = c; MoveToNextChar(); } #endif else if (wxIsdigit(c)) { // numbers while (NotEOF() && CharInString(CurrentChar(), _T("0123456789.abcdefABCDEFXxLl"))) MoveToNextChar(); if (IsEOF()) return wxEmptyString; str = m_Buffer.Mid(start, m_TokenIndex - start); } else if ( (c == '"') || (c == '\'') ) { SkipString(); //Now, we are after the end of the C-string, so return the whole string as a token. str = m_Buffer.Mid(start, m_TokenIndex - start); } else if (c == ':') { if (NextChar() == ':') { MoveToNextChar(); MoveToNextChar(); // this only copies a pointer, but operator= allocates memory and does a memcpy! str.assign(TokenizerConsts::colon_colon); } else { MoveToNextChar(); str.assign(TokenizerConsts::colon); } } else if (c == '<') { if (m_State&tsSingleAngleBrace) { if ( !SkipToOneOfChars( _T(">"), true, true) ) return wxEmptyString; MoveToNextChar(); str= m_Buffer.Mid(start, m_TokenIndex - start); } else { str = c; MoveToNextChar(); } } else if (c == '(') { if (m_State & tsReadRawExpression) { str = c; MoveToNextChar(); } else { ReadParentheses(str); } } else { if (c == '{') ++m_NestLevel; else if (c == '}') --m_NestLevel; str = c; MoveToNextChar(); } if (m_FirstRemainingLength != 0 && m_BufferLen - m_FirstRemainingLength < m_TokenIndex) { m_FirstRemainingLength = 0; m_IsReplaceParsing = false; m_RepeatReplaceCount = 0; } if (needReplace && m_State ^ tsReadRawExpression) MacroReplace(str); return str; }
wxString wxExpandEnvVars(const wxString& str) { wxString strResult; strResult.Alloc(str.length()); size_t m; for ( size_t n = 0; n < str.length(); n++ ) { switch ( str[n].GetValue() ) { #ifdef __WXMSW__ case wxT('%'): #endif //WINDOWS case wxT('$'): { Bracket bracket; #ifdef __WXMSW__ if ( str[n] == wxT('%') ) bracket = Bracket_Windows; else #endif //WINDOWS if ( n == str.length() - 1 ) { bracket = Bracket_None; } else { switch ( str[n + 1].GetValue() ) { case wxT('('): bracket = Bracket_Normal; n++; // skip the bracket break; case wxT('{'): bracket = Bracket_Curly; n++; // skip the bracket break; default: bracket = Bracket_None; } } m = n + 1; while ( m < str.length() && (wxIsalnum(str[m]) || str[m] == wxT('_')) ) m++; wxString strVarName(str.c_str() + n + 1, m - n - 1); #ifdef __WXWINCE__ const bool expanded = false; #else // NB: use wxGetEnv instead of wxGetenv as otherwise variables // set through wxSetEnv may not be read correctly! bool expanded = false; wxString tmp; if (wxGetEnv(strVarName, &tmp)) { strResult += tmp; expanded = true; } else #endif { // variable doesn't exist => don't change anything #ifdef __WXMSW__ if ( bracket != Bracket_Windows ) #endif if ( bracket != Bracket_None ) strResult << str[n - 1]; strResult << str[n] << strVarName; } // check the closing bracket if ( bracket != Bracket_None ) { if ( m == str.length() || str[m] != (wxChar)bracket ) { // under MSW it's common to have '%' characters in the registry // and it's annoying to have warnings about them each time, so // ignroe them silently if they are not used for env vars // // under Unix, OTOH, this warning could be useful for the user to // understand why isn't the variable expanded as intended #ifndef __WXMSW__ wxLogWarning(_("Environment variables expansion failed: missing '%c' at position %u in '%s'."), (char)bracket, (unsigned int) (m + 1), str.c_str()); #endif // __WXMSW__ } else { // skip closing bracket unless the variables wasn't expanded if ( !expanded ) strResult << (wxChar)bracket; m++; } } n = m - 1; // skip variable name } break; case wxT('\\'): // backslash can be used to suppress special meaning of % and $ if ( n != str.length() - 1 && (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) { strResult += str[++n]; break; } //else: fall through default: strResult += str[n]; } } return strResult; }
// ---------------------------------------------------------------------------- wxString clKeyboardManager::KeyCodeToString(int keyCode) //(2019/02/25) // ---------------------------------------------------------------------------- { wxString res; //LOGIT("KeyCodeToString_IN:keyCode[%d]char[%c]", keyCode, keyCode ); switch (keyCode) { // IGNORED KEYS // --------------------------- case WXK_START: case WXK_LBUTTON: case WXK_RBUTTON: case WXK_MBUTTON: case WXK_CLEAR: case WXK_PAUSE: case WXK_NUMLOCK: case WXK_SCROLL : wxLogDebug(wxT("wxKeyBind::KeyCodeToString - ignored key: [%d]"), keyCode); return wxEmptyString; // these must be ABSOLUTELY ignored: they are key modifiers // we won't output any LOG message since these keys could be pressed // for long time while the user choose its preferred keycombination: // this would result into a long long queue of "ignored key" messages // which would be useless even in debug builds... case WXK_SHIFT: case WXK_CONTROL: case WXK_ALT: //+v0.5 return wxEmptyString; // FUNCTION KEYS // --------------------------- case WXK_F1: case WXK_F2: case WXK_F3: case WXK_F4: case WXK_F5: case WXK_F6: case WXK_F7: case WXK_F8: case WXK_F9: case WXK_F10: case WXK_F11: case WXK_F12: case WXK_F13: case WXK_F14: case WXK_F15: case WXK_F16: case WXK_F17: case WXK_F18: case WXK_F19: case WXK_F20: case WXK_F21: case WXK_F22: case WXK_F23: case WXK_F24: res << wxT('F') << wxString::Format(_T("%d"), keyCode - WXK_F1 + 1); break; // MISCELLANEOUS KEYS // --------------------------- case WXK_BACK: res << wxT("BACK"); break; case WXK_TAB: res << wxT("TAB"); break; case WXK_RETURN: res << wxT("RETURN"); break; case WXK_ESCAPE: res << wxT("ESCAPE"); break; case WXK_SPACE: res << wxT("SPACE"); break; case WXK_DELETE: res << wxT("DELETE"); break; case WXK_MULTIPLY: res << wxT("*"); break; case WXK_ADD: res << wxT("+"); break; case WXK_SEPARATOR: res << wxT("SEPARATOR"); break; case WXK_SUBTRACT: res << wxT("-"); break; case WXK_DECIMAL: res << wxT("."); break; case WXK_DIVIDE: res << wxT("/"); break; #if not wxCHECK_VERSION(2, 8, 0) case WXK_PRIOR: res << wxT("PgUp"); break; case WXK_NEXT: res << wxT("PgDn"); break; #endif case WXK_PAGEUP: res << wxT("PAGEUP"); break; case WXK_PAGEDOWN: res << wxT("PAGEDOWN"); break; case WXK_LEFT: res << wxT("LEFT"); break; case WXK_UP: res << wxT("UP"); break; case WXK_RIGHT: res << wxT("RIGHT"); break; case WXK_DOWN: res << wxT("DOWN"); break; case WXK_SELECT: res << wxT("SELECT"); break; case WXK_PRINT: res << wxT("PRINT"); break; case WXK_EXECUTE: res << wxT("EXECUTE"); break; case WXK_SNAPSHOT: res << wxT("SNAPSHOT"); break; case WXK_INSERT: res << wxT("INSERT"); break; case WXK_HELP: res << wxT("HELP"); break; case WXK_CANCEL: res << wxT("CANCEL"); break; case WXK_MENU: res << wxT("MENU"); break; case WXK_CAPITAL: res << wxT("CAPITAL"); break; case WXK_END: res << wxT("END"); break; case WXK_HOME: res << wxT("HOME"); break; //+V.05 (Pecan#1#): wxIsalnm is excluding keys not num or a-z like }{ etc //+v.05 (Pecan#1#): Holding Alt shows ALT+3 A: added WXK_ALT: to above case //+v.05 (Pecan#1#): ALT +Ctrl Left/Right show in Dlg, up/Down dont. Printable? // A: wxWidgets2.6.2 returns false on modifier keys for Ctrl+Alt+UP/DOWN combination. // It returns Ctrl+Alt+PRIOR instead of UP/DOWN and shows false for ctrl & alt. // Same is true for Ctrl+Shift+UP/Down. // Alt+Shift+Up/Down work ok. default: // ASCII chars... if (wxIsalnum(keyCode)) { res << (wxChar)keyCode; break; } else if ((res=NumpadKeyCodeToString(keyCode)) != wxEmptyString) { res << wxT(" (numpad)"); // so it is clear it's different from other keys break; } else if (wxIsprint(keyCode)) { //v+0.5 res << (wxChar)keyCode; break; } else { // we couldn't create a description for the given keycode... wxLogDebug(wxT("wxKeyBind::KeyCodeToString - unknown key: [%d]"), keyCode); return wxEmptyString; } }//default //#if LOGGING // LOGIT(_T("KeyCodeToStringOUT:keyCode[%d]char[%c]Desc[%s]"), // keyCode, keyCode, res.GetData() ); //#endif return res; }//KeyCodeToString
bool ecConfigToolView::IsWordChar(wxChar c) { return wxIsalnum(c) || wxT('_')==c; }