/* * helper function use in AddHotkeyName to calculate an accelerator string * In some menus, accelerators do not perform exactly the same action as * the hotkey that perform a similar action. * this is usually the case when this action uses the current mouse position * for instance zoom action is ran from the F1 key or the Zoom menu. * a zoom uses the mouse position from a hot key and not from the menu * In this case, the accelerator if Shift+<hotkey> * But for many keys, the Shift modifier is not usable, and the accelerator is Alt+<hotkey> */ static void AddModifierToKey( wxString& aFullKey, const wxString & aKey ) { if( (aKey.Length() == 1) && (aKey[0] >= 'A') && (aKey[0] <= 'Z')) // We can use Shift+<key> as accelerator and <key> for hot key aFullKey << wxT( "\t" ) << MODIFIER_SHIFT << aKey; else // We must use Alt+<key> as accelerator and <key> for hot key aFullKey << wxT( "\t" ) << MODIFIER_ALT << aKey; }
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) { wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); m_titles[pos] = label; if ( !IsAttached() ) { return; } //else: have to modify the existing menu int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos); UINT id; UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION); if ( flagsOld == 0xFFFFFFFF ) { wxLogLastError(wxT("GetMenuState")); return; } if ( flagsOld & MF_POPUP ) { // HIBYTE contains the number of items in the submenu in this case flagsOld &= 0xff; id = (UINT)::GetSubMenu((HMENU)m_hMenu, mswpos); } else { id = pos; } #ifdef __WXWINCE__ MENUITEMINFO info; wxZeroMemory(info); info.cbSize = sizeof(info); info.fMask = MIIM_TYPE; info.fType = MFT_STRING; info.cch = label.Length(); info.dwTypeData = (LPTSTR) label.c_str(); if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) ) { wxLogLastError(wxT("SetMenuItemInfo")); } #else if ( ::ModifyMenu(GetHmenu(), mswpos, MF_BYPOSITION | MF_STRING | flagsOld, id, label) == (int)0xFFFFFFFF ) { wxLogLastError(wxT("ModifyMenu")); } #endif Refresh(); }
int DebuggerTree::FindCommaPos(const wxString& str) { // comma is a special case because it separates the fields // but it can also appear in a function/template signature, where // we shouldn't treat it as a field separator // what we 'll do now, is decide if the comma is inside // a function signature. // we 'll do it by counting the opening and closing parenthesis/angled-brackets // *up to* the comma. // if they 're equal, it's a field separator. // if they 're not, it's in a function signature // ;) int len = str.Length(); int i = 0; int parCount = 0; int braCount = 0; bool inQuotes = false; while (i < len) { wxChar ch = str.GetChar(i); switch (ch) { case _T('('): ++parCount; // increment on opening parenthesis break; case _T(')'): --parCount; // decrement on closing parenthesis break; case _T('<'): ++braCount; // increment on opening angle bracket break; case _T('>'): --braCount; // decrement on closing angle bracket break; case _T('"'): // fall through case _T('\''): inQuotes = !inQuotes; // toggle inQuotes flag break; default: break; } // if it's not inside quotes *and* we have parCount == 0, it's a field separator if (!inQuotes && parCount == 0 && braCount == 0 && ch == _T(',')) return i; ++i; } return -1; }
void MyApp::NewWindow(wxString file,bool batchmode) { int x = 40, y = 40, h = 650, w = 950, m = 0; int rs = 0; int display_width = 1024, display_height = 768; bool have_pos; wxConfig *config = (wxConfig *)wxConfig::Get(); wxDisplaySize(&display_width, &display_height); have_pos = config->Read(wxT("pos-x"), &x); config->Read(wxT("pos-y"), &y); config->Read(wxT("pos-h"), &h); config->Read(wxT("pos-w"), &w); config->Read(wxT("pos-max"), &m); config->Read(wxT("pos-restore"), &rs); if (rs == 0) have_pos = false; if (!have_pos || m == 1 || x > display_width || y > display_height || x < 0 || y < 0) { x = 40; y = 40; h = 650; w = 950; } #if defined __WXMAC__ x += topLevelWindows.GetCount()*20; y += topLevelWindows.GetCount()*20; #endif m_frame = new wxMaxima((wxFrame *)NULL, -1, _("wxMaxima"), wxPoint(x, y), wxSize(w, h)); m_frame->Move(wxPoint(x, y)); m_frame->SetSize(wxSize(w, h)); if (m == 1) m_frame->Maximize(true); if (file.Length() > 0 && wxFileExists(file)) { m_frame->SetOpenFile(file); } m_frame->SetBatchMode(batchmode); #if defined __WXMAC__ topLevelWindows.Append(m_frame); if (topLevelWindows.GetCount()>1) m_frame->SetTitle(wxString::Format(_("untitled %d"), ++window_counter)); #endif SetTopWindow(m_frame); m_frame->Show(true); m_frame->InitSession(); m_frame->ShowTip(false); }
void HelpPlugin::SetManPageDirs(MANFrame *manFrame) { const wxString man_prefix = _T("man:"); wxString all_man_dirs(man_prefix); for (HelpCommon::HelpFilesVector::const_iterator i = m_Vector.begin(); i != m_Vector.end(); ++i) { if (i->second.name.Mid(0, man_prefix.size()).CmpNoCase(man_prefix) == 0) { // only add ; if a dir is already set if (all_man_dirs.Length() > man_prefix.Length()) all_man_dirs += _T(";"); all_man_dirs += i->second.name.Mid(man_prefix.Length()); } } manFrame->SetDirs(all_man_dirs); }
std::string formatStringToGerber( const wxString& aString ) { /* format string means convert any code > 0x7F and unautorized code to a hexadecimal * 16 bits sequence unicode * unautorized codes are ',' '*' '%' '\' */ std::string txt; txt.reserve( aString.Length() ); for( unsigned ii = 0; ii < aString.Length(); ++ii ) { unsigned code = aString[ii]; bool convert = false; switch( code ) { case '\\': case '%': case '*': case ',': convert = true; break; default: break; } if( convert || code > 0x7F ) { txt += '\\'; // Convert code to 4 hexadecimal digit // (Gerber allows only 4 hexadecimal digit) char hexa[32]; sprintf( hexa,"%4.4X", code & 0xFFFF); txt += hexa; } else txt += char( code ); } return txt; }
bool CPhone::parseAndFormat(const wxString& val, wxString& formattedNr) { initClass(); bool rc; if (isInternalNumber(val)) { formattedNr = val; rc = val.IsNumber(); } else { PhoneNumber phoneNr; std::string strCC = m_Prefs->getPrefs().getCC(); std::string strAC = m_Prefs->getPrefs().getAC(); bool bAddAC = m_Prefs->getPrefs().addACIfShortLen(); int nLocalMaxLen = m_Prefs->getPrefs().getLocalNrMaxLen(); PhoneNumberUtil::ErrorType err = m_PhoneUtil->ParseAndKeepRawInput( val.ToUTF8().data(), strCC, &phoneNr); if (err == PhoneNumberUtil::NO_PARSING_ERROR) { std::string number; if (bAddAC && !strAC.empty() && (val.Length() < nLocalMaxLen)) { // When we have an AreaCode set in the preferences and the number // entered is too short to contain an area code then add it and // parse/format again. // NOTE: Because Area Codes are ambiguous this can produce unexpected // results or simply not work at all. std::string nsn; m_PhoneUtil->GetNationalSignificantNumber(phoneNr, &nsn); number = strAC; number += nsn; err = m_PhoneUtil->Parse(number, strCC, &phoneNr); if (err == PhoneNumberUtil::NO_PARSING_ERROR) { m_PhoneUtil->Format(phoneNr, PhoneNumberUtil::INTERNATIONAL, &number); formattedNr = wxString::FromUTF8(number.c_str()); rc = true; } else { formattedNr = val; rc = false; } } else { m_PhoneUtil->Format(phoneNr, PhoneNumberUtil::INTERNATIONAL, &number); formattedNr = wxString::FromUTF8(number.c_str()); rc = true; } } else { formattedNr = val; rc = false; } } return rc; }
bool wxSTEditorNotebook::LoadFile( const wxFileName &fileName_, const wxString &extensions_, const wxString& encoding_ref) { wxString encoding(encoding_ref); wxFileName fileName(fileName_); wxString extensions(extensions_.Length() ? extensions_ : GetOptions().GetDefaultFileExtensions()); if (fileName.GetFullPath().IsEmpty()) { wxSTEditorFileDialog fileDialog( this, _("Open file into new notebook page"), GetOptions().GetDefaultFilePath(), extensions, wxFD_OPEN | wxFD_FILE_MUST_EXIST); fileDialog.m_encoding = encoding; if (fileDialog.ShowModal() == wxID_OK) { fileName = fileDialog.GetPath(); encoding = fileDialog.m_encoding; } else return false; } bool ok = fileName.FileExists(); if (ok) { // load the file from disk and only load it once GetOptions().SetDefaultFilePath(fileName.GetPath()); int page = FindEditorPageByFileName(fileName); if (page != wxNOT_FOUND) { ok = GetEditor(page)->LoadFile(fileName, wxEmptyString, true, encoding); SetSelection(page); } else if ( (GetEditor() == NULL) || GetEditor()->IsModified() || GetEditor()->IsFileFromDisk()) // non-empty editor? { // new splitter+editor wxSTEditorSplitter *splitter = CreateSplitter(wxID_ANY); wxCHECK_MSG(splitter, false, wxT("Invalid splitter")); ok = splitter->GetEditor()->LoadFile(fileName, wxEmptyString, true, encoding); if (ok) { ok = InsertEditorSplitter(-1, splitter, true); } } else // empty editor { // reuse editor ok = GetEditor()->LoadFile(fileName, wxEmptyString, true, encoding); } } return ok; }
static bool wxIsAlphaNumeric(const wxString& val) { int i; for ( i = 0; i < (int)val.Length(); i++) { if (!wxIsalnum(val[i])) return false; } return true; }
bool wxTextValidator::IsNotInCharExcludes(const wxString& val) { size_t i; for ( i = 0; i < val.Length(); i++) { if (m_excludes.Index((wxString) val[i]) != wxNOT_FOUND) return false; } return true; }
bool Tokenizer::InitFromBuffer(const wxString& buffer, const wxString& fileOfBuffer, size_t initLineNumber) { BaseInit(); m_BufferLen = buffer.Length(); m_Buffer = buffer + _T(" "); // + 1 => sentinel m_IsOK = true; m_Filename = fileOfBuffer; m_LineNumber = initLineNumber; return true; }
bool XMLValueChecker::IsGoodString(const wxString str) { size_t len = str.Length(); int nullIndex = str.Find('\0', false); if ((len < 2048) && // Shouldn't be any reason for longer strings, except intentional file corruption. (nullIndex == -1)) // No null characters except terminator. return true; else return false; // good place for a breakpoint }
int PHPEditorContextMenu::RemoveComment(wxStyledTextCtrl* sci, int posFrom, const wxString& value) { sci->SetAnchor(posFrom); int posTo = posFrom; for(int i = 0; i < (int)value.Length(); i++) posTo = sci->PositionAfter(posTo); sci->SetSelection(posFrom, posTo); sci->DeleteBack(); return posTo - posFrom; }
// return a hash of a calltip context (to avoid storing strings of each calltip) // used in m_CallTipChoiceDict and m_CallTipFuzzyChoiceDict static int CallTipToInt(const wxString& firstTip, int numPages) { int val = 33 * firstTip.Length() ^ numPages; for (wxString::const_iterator itr = firstTip.begin(); itr != firstTip.end(); ++itr) { val = 33 * val ^ static_cast<int>(*itr); } return val; }
//--------------------------------------------------------- void CSAGA_Frame::Set_Project_Name(wxString Project_Name) { if( Project_Name.Length() > 0 ) { SetTitle(wxString::Format(wxT("%s [%s]"), SAGA_CAPTION, Project_Name.c_str())); } else { SetTitle(SAGA_CAPTION); } }
wxString sanitizePath(const wxString &path) { if (path.Length()) { wxFileName fn = path; fn.Normalize(); return fn.GetLongPath(); } return wxEmptyString; }
wxString EffectNyquist::UnQuote(wxString s) { wxString out; int len = s.Length(); if (len >= 2 && s[0] == wxT('\"') && s[len - 1] == wxT('\"')) { return s.Mid(1, len - 2); } return s; }
bool XMLValueChecker::IsGoodFileString(wxString str) { return (IsGoodString(str) && !str.IsEmpty() && // FILENAME_MAX is 260 in MSVC, but inconsistent across platforms, // sometimes huge, but we use 260 for all platforms. (str.Length() <= 260) && (str.Find(wxFileName::GetPathSeparator()) == -1)); // No path separator characters. }
wxString wxFileSystemHandler::GetLeftLocation(const wxString& location) const { int i; bool fnd = false; for (i = location.Length()-1; i >= 0; i--) { if ((location[i] == wxT(':')) && (i != 1 /*win: C:\path*/)) fnd = true; else if (fnd && (location[i] == wxT('#'))) return location.Left(i); } return wxEmptyString; }
bool CodeEdit::Untabify(wxString& text) const { // wxString::Replace is very slow with a big string because the operation // is performed in place (which requires a lot of copying). Instead we use // a different method with a second string. assert(m_indentationSize < 32); char indentation[32]; memset(indentation, ' ', 32); indentation[m_indentationSize] = 0; wxString result; result.reserve(text.Length()); unsigned int numTabs = 0; for (unsigned int i = 0; i < text.Length(); ++i) { if (text[i] == '\t') { result += indentation; ++numTabs; } else { result += text[i]; } } if (numTabs > 0) { text = result; return true; } return false; }
bool pgConn::EndPutCopy(const wxString errormsg) { int result; // Execute the query and get the status if (errormsg.Length() == 0) result = PQputCopyEnd(conn, NULL); else result = PQputCopyEnd(conn, errormsg.mb_str(*conv)); return result == 1; }
wxString CSVQuote(const wxString& str) { wxString rc; if (str.Length()) { wxString quoted = str; quoted.Replace(wxT("\""), wxT("\"\"")); rc = wxT("\""); rc += quoted; rc += wxT("\""); } return rc; }
CStatusData::CStatusData(const wxString& text, unsigned int n) : m_data(NULL), m_n(n), m_address(), m_port(0U) { m_data = new unsigned char[20U]; ::memset(m_data, ' ', 20U); for (unsigned int i = 0U; i < text.Length() && i < 20U; i++) m_data[i] = text.GetChar(i); }
int wxListCtrlEx::FindItemWithPrefix(const wxString& searchPrefix, int start) { const int count = GetItemCount(); for (int i = start; i < (count + start); i++) { int item = i % count; wxString namePrefix = GetItemText(item, 0).Left(searchPrefix.Length()); if (!namePrefix.CmpNoCase(searchPrefix)) return i % count; } return -1; }
void wxSTEditorFindReplacePanel::UpdateButtons() { // Can't search backwards when using regexp if (m_regexpFindCheckBox->GetValue() && m_backwardsCheckBox->IsEnabled()) { m_backwardsCheckBox->SetValue(false); m_backwardsCheckBox->Enable(false); } else if (!m_regexpFindCheckBox->GetValue() && !m_backwardsCheckBox->IsEnabled()) { m_backwardsCheckBox->Enable(true); } // update the find/replace button state const wxString findStr = m_findCombo->GetValue(); bool enable = findStr.Length() > 0u; wxSTEditor *edit = GetEditor(); int flags = GetFindFlags(); if (enable) { bool changed = edit ? ((edit->GetFindString() != findStr)||(edit->GetFindFlags() != flags)) : true; enable &= ((edit && edit->CanFind()) ? true : changed); } if (m_findButton->IsEnabled() != enable) m_findButton->Enable(enable); if (HasFlag(wxFR_REPLACEDIALOG)) { // Don't want recursive find if (m_findReplaceData->StringCmp(findStr, m_replaceCombo->GetValue(), flags)) enable = false; if (m_replaceAllButton && (m_replaceAllButton->IsEnabled() != enable)) m_replaceAllButton->Enable(enable); wxString selText = edit ? edit->GetSelectedText() : wxString(wxEmptyString); // can only replace if already selecting the "find" text if (enable && edit && !edit->SelectionIsFindString(findStr, flags)) enable = false; else if (!m_regexpFindCheckBox->IsChecked() && !m_findReplaceData->StringCmp(findStr, selText, flags)) enable = false; if (m_replaceButton->IsEnabled() != enable) m_replaceButton->Enable(enable); if (m_replaceFindButton->IsEnabled() != enable) m_replaceFindButton->Enable(enable); } }
static bool wxIsNumeric(const wxString& val) { for (unsigned int i = 0; i < val.Length(); ++i) { // Allow for "," (French) as well as "." -- in future we should // use wxSystemSettings or other to do better localisation if (!wxIsNumeric(val[i])) return false; } return true; }
// Inserts 2 string of text at the current insertion point. It is split into 2 strings // so that can (a) Highlight a swatch of text and the start and ending text gets put // on either side of the selected text, or (b) if no text selected, then backspace the // caret to right before the ending text, so that when add a <h1></h1>, the caret gets // placed in a logical place: <h1>|</h1> void editor_dialog::stc_or_textctrl_insert_text ( wxString starting_text_to_insert, // Text to insert at start of selection wxString ending_text_to_insert, // Text to insert at end of a selection bool tag_can_insert_newline // Whether prudent to ever insert a '\n' ) { wxString selected_text; // Currently selected text in the control // Add a trailing linefeed to the ending text, if so requested by the user in the // editor preferences, and it is prudent to do so (ie a newline after a <i> </i> doesn't // make sense. bool insert_a_linefeed = the_configuration->Read( wxT( "/PLUCKER_DESKTOP/editor_tools_insert_linefeeds"), 1L); if ( insert_a_linefeed && tag_can_insert_newline ) { ending_text_to_insert += wxT( "\n" ); } long selection_starting_caret_position; long selection_ending_caret_position; m_editor_textctrl->GetSelection( &selection_starting_caret_position, &selection_ending_caret_position ); // If selection starting caret position equals the end, that means was no selection if ( selection_starting_caret_position == selection_ending_caret_position ) { long original_caret_position = m_editor_textctrl->GetInsertionPoint(); // No text selected, just add the two strings at the insertion point m_editor_textctrl->WriteText( starting_text_to_insert ); m_editor_textctrl->WriteText( ending_text_to_insert ); // Now set the cursor to between the starting and ending text. The previous // insertion text ends up at the the original caret position, so just fast-forward // the length of the starting text long length_of_starting_text_to_insert = (long) starting_text_to_insert.Length(); long new_caret_position = original_caret_position + length_of_starting_text_to_insert; m_editor_textctrl->SetInsertionPoint( new_caret_position ); } else { // Some text is selected, so put the ending_text at the end of the selected text, // and the starting text before the selected text. // Set the insertion point to selection end, then insert ending text m_editor_textctrl->SetInsertionPoint( selection_ending_caret_position ); m_editor_textctrl->WriteText( ending_text_to_insert ); // Set the insertion point to selection end, then insert ending text m_editor_textctrl->SetInsertionPoint( selection_starting_caret_position ); m_editor_textctrl->WriteText( starting_text_to_insert ); } // Set the focus from the toolbar, back to the TextCtrl. m_editor_textctrl->SetFocus(); }
wxString CImportDialog::DecodeLegacyPassword(wxString pass) { wxString output; const char* key = "FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int pos = (pass.Length() / 3) % strlen(key); for (unsigned int i = 0; i < pass.Length(); i += 3) { if (pass[i] < '0' || pass[i] > '9' || pass[i + 1] < '0' || pass[i + 1] > '9' || pass[i + 2] < '0' || pass[i + 2] > '9') return _T(""); int number = (pass[i] - '0') * 100 + (pass[i + 1] - '0') * 10 + pass[i + 2] - '0'; wxChar c = number ^ key[(i / 3 + pos) % strlen(key)]; output += c; } return output; }
wxString HtmlEntities(const wxString &str) { wxString ret; for (unsigned int x = 0; x < str.Length(); x++) { if (str[x] != 13) ret += GetHtmlEntity(str[x]); } return ret; }
bool PPToken::readInitList(const wxString &in, int from, wxString& initList, wxArrayString& initListArr) { if((int)in.Length() < from) { return false; } wxString tmpString = in.Mid(from); int start = tmpString.Find(wxT("(")); if(start == wxNOT_FOUND ) { return false; } tmpString = tmpString.Mid(start+1); for(size_t i=0; i<(size_t)start; i++) { initList << wxT(" "); } initList << wxT("("); wxString word; int depth(1); for(size_t i=0; i<tmpString.Length(); i++) { wxChar ch = tmpString[i]; initList << ch; switch(ch) { case wxT(')'): depth --; if(depth == 0) { initListArr.Add(word); return true; } else { word << ch; } break; case wxT('('): depth++; word << ch; break; case wxT(','): if(depth == 1) { initListArr.Add(word); word.Clear(); } else { word << ch; } break; default: word << ch; break; } } return false; }