bool wxLocale::DoInit(const wxString& name, const wxString& shortName, const wxString& locale) { wxASSERT_MSG( !m_initialized, wxS("you can't call wxLocale::Init more than once") ); m_initialized = true; m_strLocale = name; m_strShort = shortName; m_language = wxLANGUAGE_UNKNOWN; // change current locale (default: same as long name) wxString szLocale(locale); if ( szLocale.empty() ) { // the argument to setlocale() szLocale = shortName; wxCHECK_MSG( !szLocale.empty(), false, wxS("no locale to set in wxLocale::Init()") ); } const char *oldLocale = wxSetlocale(LC_ALL, szLocale); if ( oldLocale ) m_pszOldLocale = wxStrdup(oldLocale); else m_pszOldLocale = NULL; if ( m_pszOldLocale == NULL ) { wxLogError(_("locale '%s' cannot be set."), szLocale); } // the short name will be used to look for catalog files as well, // so we need something here if ( m_strShort.empty() ) { // FIXME I don't know how these 2 letter abbreviations are formed, // this wild guess is surely wrong if ( !szLocale.empty() ) { m_strShort += (wxChar)wxTolower(szLocale[0]); if ( szLocale.length() > 1 ) m_strShort += (wxChar)wxTolower(szLocale[1]); } } return true; }
FastFormatUnicode &FastFormatUnicode::ToLower() { wxChar *ch = (wxChar *)m_dest.GetPtr(); for (uint i = 0; i < m_Length; ++i, ++ch) *ch = (wxChar)wxTolower(*ch); return *this; }
// multi-part ISO support is provided for FAT32 compatibility; so that large 4GB+ isos // can be split into multiple smaller files. // // Returns TRUE if multiple parts for the ISO are found. Returns FALSE if only one // part is found. void isoFile::FindParts() { wxFileName nameparts( m_filename ); wxString curext( nameparts.GetExt() ); wxChar prefixch = wxTolower(curext[0]); // Multi-part rules! // * The first part can either be the proper extension (ISO, MDF, etc) or the numerical // extension (I00, I01, M00, M01, etc). // * Numerical extensions MUST begin at 00 (I00 etc), regardless of if the first part // is proper or numerical. uint i = 0; if ((curext.Length() == 3) && (curext[1] == L'0') && (curext[2] == L'0')) { // First file is an OO, so skip 0 in the loop below: i = 1; } FastFormatUnicode extbuf; extbuf.Write( L"%c%02u", prefixch, i ); nameparts.SetExt( extbuf ); if (!pxFileExists_WithExt(nameparts, extbuf)) return; DevCon.WriteLn( Color_Blue, "isoFile: multi-part %s detected...", curext.Upper().c_str() ); ConsoleIndentScope indent; for (; i < MaxSplits; ++i) { extbuf.Clear(); extbuf.Write( L"%c%02u", prefixch, i ); if (!pxFileExists_WithExt(nameparts, extbuf)) break; _IsoPart& thispart( m_parts[m_numparts] ); thispart.handle = new wxFileInputStream( nameparts.GetFullPath() ); pxStream_OpenCheck( *thispart.handle, nameparts.GetFullPath(), L"reading" ); m_blocks += thispart.CalculateBlocks( m_blocks, m_blocksize ); DevCon.WriteLn( Color_Blue, L"\tblocks %u - %u in: %s", thispart.slsn, thispart.elsn, nameparts.GetFullPath().c_str() ); ++m_numparts; } //Console.WriteLn( Color_Blue, "isoFile: multi-part ISO loaded (%u parts found)", m_numparts ); }
static void wxDoDos2UnixFilename(T *s) { if (s) while (*s) { if (*s == wxT('\\')) *s = wxT('/'); #ifdef __WINDOWS__ else *s = wxTolower(*s); // Case INDEPENDENT #endif s++; } }
wxChar wxFieldMaskData::PreProcessChar(wxChar chNewChar) { wxChar chProcessedChar=chNewChar; switch(m_eType) { case MaskDataTypeALPHAETICUPPER: chProcessedChar=(wxChar) wxToupper(chNewChar); break; case MaskDataTypeALPHAETICLOWER: chProcessedChar=(wxChar) wxTolower(chNewChar); break; } return chProcessedChar; }
bool FileUtils::NextWord(const wxString& str, size_t& offset, wxString& word, bool makeLower) { if(offset == str.size()) { return false; } size_t start = wxString::npos; word.Clear(); for(; offset < str.size(); ++offset) { wxChar ch = str[offset]; bool isWhitespace = ((ch == ' ') || (ch == '\t')); if(isWhitespace && (start != wxString::npos)) { // we found a trailing whitespace break; } else if(isWhitespace && (start == wxString::npos)) { // skip leading whitespace continue; } else if(start == wxString::npos) { start = offset; } if(makeLower) { ch = wxTolower(ch); } word << ch; } if((start != wxString::npos) && (offset > start)) { return true; } return false; }
/* static */ bool wxAcceleratorEntry::ParseAccel(const wxString& text, int *flagsOut, int *keyOut) { // the parser won't like trailing spaces wxString label = text; label.Trim(true); // the initial \t must be preserved so don't strip leading whitespaces // check for accelerators: they are given after '\t' int posTab = label.Find(wxT('\t')); if ( posTab == wxNOT_FOUND ) { return false; } // parse the accelerator string int accelFlags = wxACCEL_NORMAL; wxString current; for ( size_t n = (size_t)posTab + 1; n < label.length(); n++ ) { if ( (label[n] == '+') || (label[n] == '-') ) { if ( CompareAccelString(current, wxTRANSLATE("ctrl")) ) accelFlags |= wxACCEL_CTRL; else if ( CompareAccelString(current, wxTRANSLATE("alt")) ) accelFlags |= wxACCEL_ALT; else if ( CompareAccelString(current, wxTRANSLATE("shift")) ) accelFlags |= wxACCEL_SHIFT; else // not a recognized modifier name { // we may have "Ctrl-+", for example, but we still want to // catch typos like "Crtl-A" so only give the warning if we // have something before the current '+' or '-', else take // it as a literal symbol if ( current.empty() ) { current += label[n]; // skip clearing it below continue; } else { wxLogDebug(wxT("Unknown accel modifier: '%s'"), current.c_str()); } } current.clear(); } else // not special character { current += (wxChar) wxTolower(label[n]); } } int keyCode; const size_t len = current.length(); switch ( len ) { case 0: wxLogDebug(wxT("No accel key found, accel string ignored.")); return false; case 1: // it's just a letter keyCode = current[0U]; // if the key is used with any modifiers, make it an uppercase one // because Ctrl-A and Ctrl-a are the same; but keep it as is if it's // used alone as 'a' and 'A' are different if ( accelFlags != wxACCEL_NORMAL ) keyCode = wxToupper(keyCode); break; default: keyCode = IsNumberedAccelKey(current, wxTRANSLATE("F"), WXK_F1, 1, 12); if ( !keyCode ) { for ( size_t n = 0; n < WXSIZEOF(wxKeyNames); n++ ) { const wxKeyName& kn = wxKeyNames[n]; if ( CompareAccelString(current, kn.name) ) { keyCode = kn.code; break; } } } if ( !keyCode ) keyCode = IsNumberedAccelKey(current, wxTRANSLATE("KP_"), WXK_NUMPAD0, 0, 9); if ( !keyCode ) keyCode = IsNumberedAccelKey(current, wxTRANSLATE("SPECIAL"), WXK_SPECIAL1, 1, 20); if ( !keyCode ) { wxLogDebug(wxT("Unrecognized accel key '%s', accel string ignored."), current.c_str()); return false; } } wxASSERT_MSG( keyCode, wxT("logic error: should have key code here") ); if ( flagsOut ) *flagsOut = accelFlags; if ( keyOut ) *keyOut = keyCode; return true; }
bool wxHtmlHelpData::AddBook(const wxString& book) { wxString extension(book.Right(4).Lower()); if (extension == wxT(".zip") || #if wxUSE_LIBMSPACK extension == wxT(".chm") /*compressed html help book*/ || #endif extension == wxT(".htb") /*html book*/) { wxFileSystem fsys; wxString s; bool rt = false; #if wxUSE_LIBMSPACK if (extension == wxT(".chm")) s = fsys.FindFirst(book + wxT("#chm:*.hhp"), wxFILE); else #endif s = fsys.FindFirst(book + wxT("#zip:*.hhp"), wxFILE); while (!s.empty()) { if (AddBook(s)) rt = true; s = fsys.FindNext(); } return rt; } wxFSFile *fi; wxFileSystem fsys; wxString title = _("noname"), safetitle, start = wxEmptyString, contents = wxEmptyString, index = wxEmptyString, charset = wxEmptyString; fi = fsys.OpenFile(book); if (fi == NULL) { wxLogError(_("Cannot open HTML help book: %s"), book.c_str()); return false; } fsys.ChangePathTo(book); const wxChar *lineptr; wxChar linebuf[300]; wxString tmp; wxHtmlFilterPlainText filter; tmp = filter.ReadFile(*fi); lineptr = tmp.c_str(); do { lineptr = ReadLine(lineptr, linebuf, 300); for (wxChar *ch = linebuf; *ch != wxT('\0') && *ch != wxT('='); ch++) *ch = (wxChar)wxTolower(*ch); if (wxStrstr(linebuf, wxT("title=")) == linebuf) title = linebuf + wxStrlen(wxT("title=")); if (wxStrstr(linebuf, wxT("default topic=")) == linebuf) start = linebuf + wxStrlen(wxT("default topic=")); if (wxStrstr(linebuf, wxT("index file=")) == linebuf) index = linebuf + wxStrlen(wxT("index file=")); if (wxStrstr(linebuf, wxT("contents file=")) == linebuf) contents = linebuf + wxStrlen(wxT("contents file=")); if (wxStrstr(linebuf, wxT("charset=")) == linebuf) charset = linebuf + wxStrlen(wxT("charset=")); } while (lineptr != NULL); wxFontEncoding enc = wxFONTENCODING_SYSTEM; #if wxUSE_FONTMAP if (charset != wxEmptyString) enc = wxFontMapper::Get()->CharsetToEncoding(charset); #endif // No conversion was done on the title yet; at least // test for a common case. if (charset == wxT("utf-8") && !title.IsEmpty()) { char *buf = new char[title.Length()+1]; size_t i; for (i = 0; i < title.Length(); i++) buf[i] = (char) title[i]; buf[i] = 0; title = wxString::FromUTF8(buf); delete[] buf; } bool rtval = AddBookParam(*fi, enc, title, contents, index, start, fsys.GetPath()); delete fi; return rtval; }
bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event) { // we have a native implementation for Win32 and so don't need this one #ifndef __WIN32__ wxChar ch = 0; int keycode = event.GetKeyCode(); switch ( keycode ) { 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: ch = (wxChar)(_T('0') + keycode - WXK_NUMPAD0); break; case WXK_MULTIPLY: case WXK_NUMPAD_MULTIPLY: ch = _T('*'); break; case WXK_ADD: case WXK_NUMPAD_ADD: ch = _T('+'); break; case WXK_SUBTRACT: case WXK_NUMPAD_SUBTRACT: ch = _T('-'); break; case WXK_DECIMAL: case WXK_NUMPAD_DECIMAL: ch = _T('.'); break; case WXK_DIVIDE: case WXK_NUMPAD_DIVIDE: ch = _T('/'); break; case WXK_DELETE: case WXK_NUMPAD_DELETE: // delete the character at cursor { const long pos = GetInsertionPoint(); if ( pos < GetLastPosition() ) Remove(pos, pos + 1); } break; case WXK_BACK: // delete the character before the cursor { const long pos = GetInsertionPoint(); if ( pos > 0 ) Remove(pos - 1, pos); } break; default: #if wxUSE_UNICODE if ( event.GetUnicodeKey() ) { ch = event.GetUnicodeKey(); } else #endif if ( keycode < 256 && keycode >= 0 && wxIsprint(keycode) ) { // FIXME this is not going to work for non letters... if ( !event.ShiftDown() ) { keycode = wxTolower(keycode); } ch = (wxChar)keycode; } else { ch = _T('\0'); } } if ( ch ) { WriteText(ch); return true; } #else // __WIN32__ wxUnusedVar(event); #endif // !__WIN32__/__WIN32__ return false; }
bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event) { bool handled = false; // we have a native implementation for Win32 and so don't need this one #ifndef __WIN32__ wxChar ch = 0; int keycode = event.GetKeyCode(); long from, to; GetSelection(&from,&to); long insert = GetInsertionPoint(); long last = GetLastPosition(); // catch arrow left and right switch ( keycode ) { case WXK_LEFT: if ( event.ShiftDown() ) SetSelection( (from > 0 ? from - 1 : 0) , to ); else { if ( from != to ) insert = from; else if ( insert > 0 ) insert -= 1; SetInsertionPoint( insert ); } handled = true; break; case WXK_RIGHT: if ( event.ShiftDown() ) SetSelection( from, (to < last ? to + 1 : last) ); else { if ( from != to ) insert = to; else if ( insert < last ) insert += 1; SetInsertionPoint( insert ); } handled = true; break; 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: ch = (wxChar)(wxT('0') + keycode - WXK_NUMPAD0); break; case WXK_MULTIPLY: case WXK_NUMPAD_MULTIPLY: ch = wxT('*'); break; case WXK_ADD: case WXK_NUMPAD_ADD: ch = wxT('+'); break; case WXK_SUBTRACT: case WXK_NUMPAD_SUBTRACT: ch = wxT('-'); break; case WXK_DECIMAL: case WXK_NUMPAD_DECIMAL: ch = wxT('.'); break; case WXK_DIVIDE: case WXK_NUMPAD_DIVIDE: ch = wxT('/'); break; case WXK_DELETE: case WXK_NUMPAD_DELETE: // delete the character at cursor { const long pos = GetInsertionPoint(); if ( pos < GetLastPosition() ) Remove(pos, pos + 1); handled = true; } break; case WXK_BACK: // delete the character before the cursor { const long pos = GetInsertionPoint(); if ( pos > 0 ) Remove(pos - 1, pos); handled = true; } break; default: #if wxUSE_UNICODE if ( event.GetUnicodeKey() ) { ch = event.GetUnicodeKey(); } else #endif if ( keycode < 256 && keycode >= 0 && wxIsprint(keycode) ) { // FIXME this is not going to work for non letters... if ( !event.ShiftDown() ) { keycode = wxTolower(keycode); } ch = (wxChar)keycode; } else { ch = wxT('\0'); } } if ( ch ) { WriteText(ch); handled = true; } #else // __WIN32__ wxUnusedVar(event); #endif // !__WIN32__/__WIN32__ return handled; }
// get error message from system const wxChar *wxSysErrorMsg(unsigned long nErrCode) { if ( nErrCode == 0 ) nErrCode = wxSysErrorCode(); #if defined(__WXMSW__) && !defined(__WXMICROWIN__) static wxChar s_szBuf[1024]; // get error message from system LPVOID lpMsgBuf; if ( ::FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, nErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL ) == 0 ) { // if this happens, something is seriously wrong, so don't use _() here // for safety wxSprintf(s_szBuf, _T("unknown error %lx"), nErrCode); return s_szBuf; } // copy it to our buffer and free memory // Crashes on SmartPhone (FIXME) #if !defined(__SMARTPHONE__) /* of WinCE */ if( lpMsgBuf != 0 ) { wxStrncpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1); s_szBuf[WXSIZEOF(s_szBuf) - 1] = wxT('\0'); LocalFree(lpMsgBuf); // returned string is capitalized and ended with '\r\n' - bad s_szBuf[0] = (wxChar)wxTolower(s_szBuf[0]); size_t len = wxStrlen(s_szBuf); if ( len > 0 ) { // truncate string if ( s_szBuf[len - 2] == wxT('\r') ) s_szBuf[len - 2] = wxT('\0'); } } else #endif // !__SMARTPHONE__ { s_szBuf[0] = wxT('\0'); } return s_szBuf; #else // !__WXMSW__ #if wxUSE_UNICODE static wchar_t s_wzBuf[1024]; wxConvCurrent->MB2WC(s_wzBuf, strerror((int)nErrCode), WXSIZEOF(s_wzBuf) - 1); return s_wzBuf; #else return strerror((int)nErrCode); #endif #endif // __WXMSW__/!__WXMSW__ }
// Do the search long MainWindow::DoSearch(void) { if (m_searchString.empty()) return false; FILE *file; size_t i = 0; int ch = 0; wxChar buf[100]; long find_start; long previous_poem_start; bool found = false; size_t search_length = m_searchString.length(); if (same_search) { find_start = last_find + 1; previous_poem_start = last_poem_start; } else { find_start = 0; last_poem_start = 0; previous_poem_start = -1; } if (data_filename) wxSprintf(buf, wxT("%s.dat"), data_filename); file = wxFopen(buf, wxT("rb")); if (! (data_filename && file)) { wxSprintf(error_buf, wxT("Poetry data file %s not found\n"), buf); PoetryError(error_buf); return false; } fseek(file, find_start, SEEK_SET); while ((ch != EOF) && !found) { ch = getc(file); ch = wxTolower(ch); // Make lower case // Only match if we're looking at a different poem // (no point in displaying the same poem again) if ((m_searchString[i] == ch) && (last_poem_start != previous_poem_start)) { if (i == 0) last_find = ftell(file); if (i == search_length-1) found = true; i ++; } else { i = 0; } if (ch == '#') { ch = getc(file); last_poem_start = ftell(file); } } fclose(file); if (ch == EOF) { last_find = -1; } if (found) { return last_poem_start; } return -1; }
void CMuleListCtrl::OnChar(wxKeyEvent& evt) { int key = evt.GetKeyCode(); if (key == 0) { // We prefer GetKeyCode() to GetUnicodeKey(), in order to work // around a bug in the GetUnicodeKey(), that causes values to // be returned untranslated. This means for instance, that if // shift and '1' is pressed, the result is '1' rather than '!' // (as it should be on my keyboard). This has been reported: // http://sourceforge.net/tracker/index.php?func=detail&aid=1864810&group_id=9863&atid=109863 key = evt.GetUnicodeKey(); } else if (key >= WXK_START) { // wxKeycodes are ignored, as they signify events such as the 'home' // button. Unicoded chars are not checked as there is an overlap valid // chars and the wx keycodes. evt.Skip(); return; } // We wish to avoid handling shortcuts, with the exception of 'select-all'. if (evt.AltDown() || evt.ControlDown() || evt.MetaDown()) { if (evt.CmdDown() && (evt.GetKeyCode() == 0x01)) { // Ctrl+a (Command+a on Mac) was pressed, select all items for (int i = 0; i < GetItemCount(); ++i) { SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } } evt.Skip(); return; } else if (m_tts_time + 1500u < GetTickCount()) { m_tts_text.Clear(); } m_tts_time = GetTickCount(); m_tts_text.Append(wxTolower(key)); // May happen if the subclass does not forward deletion events. // Or rather when single-char-repeated (see below) wraps around, so don't assert. if (m_tts_item >= GetItemCount()) { m_tts_item = -1; } unsigned next = (m_tts_item == -1) ? 0 : m_tts_item; for (unsigned i = 0, count = GetItemCount(); i < count; ++i) { wxString text = GetTTSText((next + i) % count).MakeLower(); if (text.StartsWith(m_tts_text)) { ClearSelection(); m_tts_item = (next + i) % count; SetItemState(m_tts_item, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED); EnsureVisible(m_tts_item); return; } } if (m_tts_item != -1) { // Crop the string so that it matches the old item (avoid typos). wxString text = GetTTSText(m_tts_item).MakeLower(); // If the last key didn't result in a hit, then we skip the event. if (!text.StartsWith(m_tts_text)) { if ((m_tts_text.Length() == 2) && (m_tts_text[0] == m_tts_text[1])) { // Special case, single-char, repeated. This allows toggeling // between items starting with a specific letter. m_tts_text.Clear(); // Increment, so the next will be selected (or wrap around). m_tts_item++; OnChar(evt); } else { m_tts_text.RemoveLast(); evt.Skip(true); } } } else { evt.Skip(true); } }
void MultipartFileReader::FindParts() { wxFileName nameparts( m_filename ); wxString curext( nameparts.GetExt() ); wxChar prefixch = wxTolower(curext[0]); // Multi-part rules! // * The first part can either be the proper extension (ISO, MDF, etc) or the numerical // extension (I00, I01, M00, M01, etc). // * Numerical extensions MUST begin at 00 (I00 etc), regardless of if the first part // is proper or numerical. uint i = 0; if ((curext.Length() == 3) && (curext[1] == L'0') && (curext[2] == L'0')) { // First file is an OO, so skip 0 in the loop below: i = 1; } FastFormatUnicode extbuf; extbuf.Write( L"%c%02u", prefixch, i ); nameparts.SetExt( extbuf ); if (!pxFileExists_WithExt(nameparts, extbuf)) return; DevCon.WriteLn( Color_Blue, "isoFile: multi-part %s detected...", WX_STR(curext.Upper()) ); ConsoleIndentScope indent; int bsize = m_parts[0].reader->GetBlockSize(); int blocks = m_parts[0].end; m_numparts = 1; for (; i < MaxParts; ++i) { extbuf.Clear(); extbuf.Write( L"%c%02u", prefixch, i ); nameparts.SetExt( extbuf ); if (!pxFileExists_WithExt(nameparts, extbuf)) break; Part* thispart = m_parts + m_numparts; AsyncFileReader* thisreader = thispart->reader = new FlatFileReader(); wxString name = nameparts.GetFullPath(); thisreader->Open(name); thisreader->SetBlockSize(bsize); thispart->start = blocks; uint bcount = thisreader->GetBlockCount(); blocks += bcount; thispart->end = blocks; DevCon.WriteLn( Color_Blue, L"\tblocks %u - %u in: %s", thispart->start, thispart->end, WX_STR(nameparts.GetFullPath()) ); ++m_numparts; } //Console.WriteLn( Color_Blue, "isoFile: multi-part ISO loaded (%u parts found)", m_numparts ); }
Tcl_UniChar Tcl_UniCharToLower(int ch) { return wxTolower(ch); }