// Save drawing to file void PaintModel::SaveImage(wxString filename, wxSize size) { wxBitmap bitmap; // Create the bitmap of the specified wxSize bitmap.Create(size); // Create a memory DC to draw to the bitmap wxMemoryDC dc(bitmap); // Clear the background color dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); // Draw all the shapes DrawShapes(dc, false); // Get the type of image file wxBitmapType type = wxBITMAP_TYPE_JPEG; if (filename.substr(filename.size() - PNG_EXT.length()) == PNG_EXT) { std::cout << "Saving PNG image: " << filename << std::endl; type = wxBITMAP_TYPE_PNG; } else if (filename.substr(filename.size() - BMP_EXT.length()) == BMP_EXT) { std::cout << "Saving BMP image: " << filename << std::endl; type = wxBITMAP_TYPE_BMP; } else { std::cout << "Saving JPG/JPEG image: " << filename << std::endl; } // Write the bitmap with the specified file name and wxBitmapType bitmap.SaveFile(filename, type); }
wxString CControlSocket::ConvertDomainName(wxString const& domain) { #ifdef __WXMSW__ int len = IdnToAscii(IDN_ALLOW_UNASSIGNED, domain, domain.size() + 1, 0, 0); if( !len ) { LogMessage(MessageType::Debug_Warning, _T("Could not convert domain name")); return domain; } wchar_t* output = new wchar_t[len]; int res = IdnToAscii(IDN_ALLOW_UNASSIGNED, domain, domain.size() + 1, output, len); if( !res ) { LogMessage(MessageType::Debug_Warning, _T("Could not convert domain name")); return domain; } wxString ret(output); delete [] output; return ret; #else wxScopedCharBuffer const utf8 = domain.utf8_str(); char *output = 0; if (idna_to_ascii_8z(utf8, &output, IDNA_ALLOW_UNASSIGNED)) { LogMessage(MessageType::Debug_Warning, _T("Could not convert domain name")); return domain; } wxString result = wxConvCurrent->cMB2WX(output); idn_free(output); return result; #endif }
unsigned long WiredCodec::Decode(const wxString &filename, t_Pcm *pcm, unsigned long length) { list<t_WLib>::const_iterator iterTWLib; unsigned long id; unsigned long retLenght = 0; WiredCodecMutex.Lock(); if (codecToUse.find(filename) != codecToUse.end()) id = codecToUse[filename]; else { pcm->pcm = NULL; WiredCodecMutex.Unlock(); return retLenght; } if (!path) { path = new char(filename.size() * sizeof(*path) + 1); strncpy(path, (const char *)filename.mb_str(*wxConvCurrent), filename.size() + 1); } for (iterTWLib = _WLib.begin(); iterTWLib != _WLib.end(); iterTWLib++) { if ((*iterTWLib).Codec->GetUniqueId() == id) { retLenght = (*iterTWLib).Codec->decode(path, pcm, length); break; } } WiredCodecMutex.Unlock(); return retLenght; }
/** * Indicates if the given checksum is valid. * * @param checksum The checksum to check. */ bool MD5File::IsValidChecksum(const wxString& checksum) { const wxString validCaracters = wxT("0123456789abcdefABCDEF"); wxChar c; size_t i, j; size_t l = checksum.size(); size_t s = validCaracters.size(); bool OK, found; i = 0; OK = (checksum.size() == 32); while (OK && i < l) { c = checksum[i]; j = 0; found = false; while (!found && j < s) { if (c == validCaracters[j]) found = true; j++; } if (!found) OK = false; i++; } return OK; }
void HtmlOutputPane::DecodePath(wxString& path) { // static // Spaces transformed to %20 in paths confuses ie for (unsigned int i2 = 0; i2 < path.size(); ++i2) { if (path[i2] == wxT('%') && path.size() > i2+3 && path[i2+1] == wxT('2') && path[i2+2] == wxT('0')) { path.replace(i2, 3, wxT(" ")); } } }
wxString FindTab(wxString &line) { for (int x = 0; x < line.size(); x++) { if (line[x] == '\t') { wxString first = line.SubString(0, x - 1); line = line.SubString(x+1, line.size()); return first; } } return line; }
bool CQueueStorage::Impl::Bind(sqlite3_stmt* statement, int index, const wxString& value) { #ifdef __WXMSW__ return sqlite3_bind_text16(statement, index, value.wc_str(), value.length() * 2, SQLITE_TRANSIENT) == SQLITE_OK; #else char* out = new char[value.size() * 2]; size_t outlen = utf16_.FromWChar(out, value.size() * 2, value.c_str(), value.size()); bool ret = sqlite3_bind_text16(statement, index, out, outlen, custom_free) == SQLITE_OK; return ret; #endif }
bool wxExEx::Move( const wxString& begin_address, const wxString& end_address, const wxString& destination) { if (m_STC->GetReadOnly()) { return false; } const int dest_line = ToLineNumber(destination); if (dest_line == 0) { return false; } if (!SetSelection(begin_address, end_address)) { return false; } if (begin_address.StartsWith("'")) { if (begin_address.size() > 1) { MarkerDelete(begin_address.GetChar(1)); } } if (end_address.StartsWith("'")) { if (end_address.size() > 1) { MarkerDelete(end_address.GetChar(1)); } } m_STC->BeginUndoAction(); m_STC->Cut(); m_STC->GotoLine(dest_line - 1); m_STC->Paste(); m_STC->EndUndoAction(); const int lines = wxExGetNumberOfLines(m_STC->GetSelectedText()); if (lines >= 2) { m_Frame->ShowExMessage(wxString::Format(_("%d lines moved"), lines)); } return true; }
void MerryParseCommandStr(const wxString& commandStr, wxString& commandName, wxString& commandArg) { bool inQM = false; bool inText = false; bool inSpace = false; // http://alter.org.ua/docs/win/args/ size_t i; for (i=0; i<commandStr.size(); ++i) { wxChar c = commandStr[i]; if (inQM) { if (c == '\"') inQM = false; else commandName += c; } else { switch (c) { case '\"': inQM = true; inText = true; if (inSpace) goto getParam; inSpace = false; break; case ' ': case '\t': case '\n': case '\r': inText = false; inSpace = true; break; default: inText = true; if (inSpace) goto getParam; commandName += c; inSpace = false; break; } } } getParam: if (i < commandStr.size()) commandArg = commandStr.Mid(i); }
void Edit::OnFindReplaceDialog(wxFindDialogEvent& event) { const wxEventType type = event.GetEventType(); const wxString find_string = m_FindData.GetFindString(); int found_start, found_end; if (type == wxEVT_FIND || type == wxEVT_FIND_NEXT) { // search if (FindText(found_start, found_end, type == wxEVT_FIND_NEXT)) { SetSelection(found_start, found_end); } else { wxMessageDialog dialog(this, wxT("Cannot find the text \"" + find_string + "\" from current position"), wxT("Find")); dialog.ShowModal(); } } else if (type == wxEVT_FIND_REPLACE) { ReplaceText(find_string); } else if (type == wxEVT_FIND_REPLACE_ALL) { const wxString replace_string = m_FindData.GetReplaceString(); int start_index = 0; bool found = true; int found_count = 0; do { // set search area SetTargetStart(start_index); SetTargetEnd(GetLastPosition()); // search and replace found_start = SearchInTarget(find_string); if (found_start > -1) { found_end = found_start + find_string.size(); SetTargetStart(found_start); SetTargetEnd(found_end); ReplaceTarget(replace_string); start_index = found_start + replace_string.size(); found_count++; } else { found = false; } } while (found); const wxString message = wxString::Format(wxT("%d occurrence(s) of \"%s\" were replaced with \"%s\"."), found_count, find_string, replace_string); wxMessageDialog replace_dialog(this, message, wxT("Replaced Text")); replace_dialog.ShowModal(); } }
wxString CUpdater::GetLocalFile( build const& b, bool allow_existing ) { wxString const fn = GetFilename( b.url_ ); wxString const dl = GetDownloadDir().GetPath(); int i = 1; wxString f = dl + fn; while( CLocalFileSystem::GetFileType(f) != CLocalFileSystem::unknown && (!allow_existing || !VerifyChecksum(f, b.size_, b.hash_))) { if( ++i > 99 ) { return _T(""); } wxString ext; int pos; if( !fn.Right(8).CmpNoCase(_T(".tar.bz2")) ) { pos = fn.size() - 8; } else { pos = fn.Find('.', true); } if( pos == -1 ) { f = dl + fn + wxString::Format(_T(" (%d)"), i); } else { f = dl + fn.Left(pos) + wxString::Format(_T(" (%d)"), i) + fn.Mid(pos); } } return f; }
wxString recEventa::SetAutoTitle( const wxString& name1, const wxString& name2 ) { f_title = wxEmptyString; wxString n1, n2; if( name1.size() ) { n1 = name1; n2 = name2; } else { n1 = name2; n2 = name1; } wxString type = recEventType::GetTypeStr( f_type_id ); if( type.size() ) { f_title << type << " of "; } else { f_title << "Unknown event for "; } if( n1.size() ) { f_title << n1; } else { f_title << "Unknown person"; } if( n2.size() ) { f_title << " and " << n2; } return f_title; }
void wxExViMacros::StartRecording(const wxString& macro) { if (m_IsRecording || macro.empty()) { return; } m_IsRecording = true; if (macro.size() == 1) { // We only use lower case macro's, to be able to // append to them using qA. m_Macro = macro.Lower(); // Clear macro if it is lower case // (otherwise append to the macro). if (wxIslower(macro[0])) { m_Macros[m_Macro].clear(); } } else { m_Macro = macro; m_Macros[m_Macro].clear(); } wxExFrame::StatusText(m_Macro, "PaneMacro"); wxLogStatus(_("Macro recording")); }
/** * Check that a string looks like a floating point number that can * be dealt with. */ static bool validateFloatField( const wxString& aStr ) { // Skip empty fields if( aStr.size() == 0 ) return false; // a single . or , doesn't count as number, although valid in a float if( aStr.size() == 1 ) { if( (aStr.compare( "." ) == 0) || (aStr.compare( "," ) == 0) ) return false; } return true; }
void CBOINCBaseView::append_to_status(wxString& existing, const wxChar* additional) { if (existing.size() == 0) { existing = additional; } else { existing = existing + wxT(", ") + additional; } }
// replace continuous spaces by one single space static inline wxString CompressSpaces(const wxString & str) { wxString buf; buf.reserve( str.size() ); bool space_counted = false; for( const wxChar * pstr = str.c_str(); *pstr; ++pstr ) { wxChar ch = *pstr; if( WHITESPACE( ch ) ) { if( space_counted ) { continue; } ch = wxT(' '); space_counted = true; } else { space_counted = false; } buf += ch; } return buf; }
void KICAD_MANAGER_FRAME::Execute( wxWindow* frame, const wxString& execFile, wxString params ) { if( params.size() ) AddDelimiterString( params ); TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( execFile ); long pid = ExecuteFile( frame, execFile, params, callback ); if( pid > 0 ) { wxString msg = wxString::Format( _( "%s %s opened [pid=%ld]\n" ), GetChars( execFile ), GetChars( params ), pid ); PrintMsg( msg ); #ifdef __WXMAC__ msg.Printf( "osascript -e 'activate application \"%s\"' ", execFile ); system( msg.c_str() ); #endif } else { delete callback; } }
wxString CImportDialog::DecodeLegacyPassword(wxString pass) { if( pass.size() % 3 ) { return wxString(); } 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 wxString(); 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 FileUtils::NormaliseName(const wxString& name) { static bool initialised = false; static int invalidChars[256]; if(!initialised) { memset(invalidChars, 0, sizeof(invalidChars)); std::vector<int> V = { '@', '-', '^', '%', '&', '$', '#', '@', '!', '(', ')', '{', '}', '[', ']', '+', '=', ';', ',', '.', ' ' }; for(size_t i = 0; i < V.size(); ++i) { invalidChars[V[i]] = 1; } initialised = true; } wxString normalisedName; for(size_t i = 0; i < name.size(); ++i) { if(invalidChars[name[i]]) { // an invalid char was found normalisedName << "_"; } else { normalisedName << name[i]; } } return normalisedName; }
wxAcceleratorEntry_v wxKeyTextCtrl::FromString(const wxString &s, wxChar sep) { wxAcceleratorEntry_v ret, empty; int mod, key; int len = s.size(); for (int lastkey = len - 1; (lastkey = s.rfind(sep, lastkey)) != wxString::npos; lastkey--) { if (lastkey == len - 1) { // sep as accel if (!lastkey) break; if (s[lastkey - 1] == wxT('-') || s[lastkey - 1] == wxT('+') || s[lastkey - 1] == sep) continue; } if (!ParseString(s.c_str() + lastkey + 1, len - lastkey - 1, mod, key)) return empty; ret.insert(ret.begin(), wxAcceleratorEntry(mod, key)); len = lastkey; } if (!ParseString(s.c_str(), len, mod, key)) return empty; ret.insert(ret.begin(), wxAcceleratorEntry(mod, key)); return ret; }
bool CAutoAsciiFiles::TransferRemoteAsAscii(wxString const& remote_file, ServerType server_type) { int mode = COptions::Get()->GetOptionVal(OPTION_ASCIIBINARY); if (mode == 1) return true; else if (mode == 2) return false; if (server_type == VMS) { return TransferRemoteAsAscii(StripVMSRevision(remote_file.ToStdWstring()), DEFAULT); } if (!remote_file.empty() && remote_file[0] == '.') return COptions::Get()->GetOptionVal(OPTION_ASCIIDOTFILE) != 0; int pos = remote_file.Find('.', true); if (pos < 0 || static_cast<unsigned int>(pos) + 1 == remote_file.size()) { return COptions::Get()->GetOptionVal(OPTION_ASCIINOEXT) != 0; } wxString ext = remote_file.Mid(pos + 1); for (auto const& ascii_ext : m_ascii_extensions) { if (!ext.CmpNoCase(ascii_ext)) { return true; } } return false; }
wxString CompressedCachePath(wxString path) { #if defined(__WXMSW__) int colon = path.find(':', 0); path.Remove(colon, 1); #endif /* replace path separators with ! */ wxChar separator = wxFileName::GetPathSeparator(); for(unsigned int pos = 0; pos < path.size(); pos = path.find(separator, pos)) path.replace(pos, 1, _T("!")); // Obfuscate the compressed chart file name, to (slightly) protect some encrypted raster chart data. wxCharBuffer buf = path.ToUTF8(); unsigned char sha1_out[20]; sha1( (unsigned char *) buf.data(), strlen(buf.data()), sha1_out ); wxString sha1; for (unsigned int i=0 ; i < 20 ; i++){ wxString s; s.Printf(_T("%02X"), sha1_out[i]); sha1 += s; } return g_Platform->GetPrivateDataDir() + separator + _T("raster_texture_cache") + separator + sha1; }
void TexFont::RenderString( const wxString &string, int x, int y ) { if(!texobj) return; glPushMatrix(); glTranslatef(x, y, 0); glPushMatrix(); glBindTexture( GL_TEXTURE_2D, texobj); for(unsigned int i=0; i<string.size(); i++) { wchar_t x = string[i]; if(x == '\n') { glPopMatrix(); glTranslatef(0, tgi[(int)'A'].height, 0); glPushMatrix(); continue; } RenderGlyph( x ); } glPopMatrix(); glPopMatrix(); }
wxArrayString clConsoleBase::SplitArguments(const wxString& args) { const int STATE_NORMAL = 0; const int STATE_DQUOTES = 1; const int STATE_ESCAPE = 2; int state = STATE_NORMAL; int prevState = STATE_NORMAL; wxArrayString outputArr; wxString curtoken; for(size_t i = 0; i < args.size(); ++i) { wxChar ch = args[i]; switch(state) { case STATE_NORMAL: { switch(ch) { case '\\': curtoken << ch; prevState = STATE_NORMAL; state = STATE_ESCAPE; break; case ' ': ADD_CURRENT_TOKEN(); break; case '"': ADD_CURRENT_TOKEN(); state = STATE_DQUOTES; break; default: curtoken << ch; break; } } break; case STATE_DQUOTES: { switch(ch) { case '\\': curtoken << ch; prevState = STATE_DQUOTES; state = STATE_ESCAPE; break; case '"': ADD_CURRENT_TOKEN(); state = STATE_NORMAL; break; default: curtoken << ch; break; } } break; case STATE_ESCAPE: curtoken << ch; state = prevState; break; default: break; } } // if we still got some unprocessed token, add it ADD_CURRENT_TOKEN(); return outputArr; }
bool StringEmptyOrWhitespace(const wxString &str) { for (size_t i = 0; i < str.size(); ++i) if (!IsWhitespace(str[i])) return false; return true; }
int HtmlDialog::ParseHex(const wxString& hexStr) { // static wxASSERT(hexStr.size() == 2); const int n1 = HexToNumber(hexStr[0]); const int n2 = HexToNumber(hexStr[1]); return ((n1 << 4) | n2); }
void InplaceConvertCRLFtoLF(wxString& text) { // WINDOWS ONLY!! newline conversion // The build-in replace is too slow so we do // it manually (at the price of some memory) //copytext.Replace(wxT("\r\n"), wxT("\n")); wxString newtext; newtext.reserve(text.size()); unsigned int lastPos = 0; for (unsigned int i = 0; i < text.size(); ++i) { if (text[i] == wxT('\r')) { newtext += text.substr(lastPos, i - lastPos); lastPos = i + 1; } } if (lastPos < text.size()) newtext += text.substr(lastPos, text.size() - lastPos); text.swap(newtext); }
bool TFlybotAPI::SendPM(const wxString& cid, const wxString& msg) { if (m_botAPI.SendMessage2 && !cid.empty() && !msg.empty()) { return m_botAPI.SendMessage2(BotInit::SEND_PM, cid.c_str(), msg.t_str(), (unsigned int)msg.size() + sizeof(wxChar)); } return false; }
void MyFrame::OnOpenDatabase(wxCommandEvent& WXUNUSED(event)) { wxString defaultDir(""); wxString defaultFile(""); if (lastDatabasePath.size() > 0) defaultDir = lastDatabasePath; if (lastDatabaseFile.size() > 0) defaultFile = lastDatabaseFile; wxFileDialog dialog(this, "Choose database file", defaultDir, defaultFile, "*.db", wxFD_OPEN | wxFD_FILE_MUST_EXIST, wxDefaultPosition, wxDefaultSize, "filedlg"); if (dialog.ShowModal() == wxID_OK) { if (tcDatabaseManager::Get()->IsOpen()) { tcDatabaseManager::Get()->Close(); SetStatusText("Closed database"); } std::string databaseFileName; databaseFileName = dialog.GetPath().c_str(); if (tcDatabaseManager::Get()->Open(databaseFileName)) { UpdatePages(); wxString fullPath = dialog.GetPath(); lastDatabasePath = fullPath.BeforeLast('\\'); lastDatabaseFile = fullPath.AfterLast('\\'); wxString msg = wxString("Editing ") + fullPath; SetStatusText(msg); } else { wxMessageBox("Open failed"); } } }
static bool isSafeUrl(const wxString &server, const wxString &safeUrl) { if (safeUrl.size()==0) return false; if (safeUrl[0] == '.') return server.Contains(safeUrl); return server == safeUrl; }