wxString wxFileSelectorEx(const wxChar *title, const wxChar *defaultDir, const wxChar *defaultFileName, int* defaultFilterIndex, const wxChar *filter, int flags, wxWindow* parent, int x, int y) { wxFileDialog fileDialog(parent, !wxIsEmpty(title) ? title : wxEmptyString, !wxIsEmpty(defaultDir) ? defaultDir : wxEmptyString, !wxIsEmpty(defaultFileName) ? defaultFileName : wxEmptyString, !wxIsEmpty(filter) ? filter : wxEmptyString, flags, wxPoint(x, y)); wxString filename; if ( fileDialog.ShowModal() == wxID_OK ) { if ( defaultFilterIndex ) *defaultFilterIndex = fileDialog.GetFilterIndex(); filename = fileDialog.GetPath(); } return filename; }
bool wxFileSystem::FindFileInPath(wxString *pStr, const wxChar *path, const wxChar *basename) { // we assume that it's not empty wxCHECK_MSG( !wxIsEmpty(basename), false, _T("empty file name in wxFileSystem::FindFileInPath")); // skip path separator in the beginning of the file name if present if ( wxIsPathSeparator(*basename) ) basename++; wxStringTokenizer tokenizer(path, wxPATH_SEP); while ( tokenizer.HasMoreTokens() ) { wxString strFile = tokenizer.GetNextToken(); if ( !wxEndsWithPathSeparator(strFile) ) strFile += wxFILE_SEP_PATH; strFile += basename; wxFSFile *file = OpenFile(strFile); if ( file ) { delete file; *pStr = strFile; return true; } } return false; }
void unLogWindow::DoLog(wxLogLevel level, const wxChar *str, time_t t) { // first let the previous logger show it wxLogPassThrough::DoLog(level, str, t); if( LogFrame ) { switch( level ) { case wxLOG_Status: // by default, these messages are ignored by wxLog, so process // them ourselves if( !wxIsEmpty(str) ) { wxString str; str << _("Status: ") << str; DoLogString(str, t); } break; // don't put trace messages in the text window for 2 reasons: // 1) there are too many of them // 2) they may provoke other trace messages thus sending a program // into an infinite loop case wxLOG_Trace: break; default: // and this will format it nicely and call our DoLogString() wxLog::DoLog(level, str, t); } } }
bool wxFileConfig::Write(const wxString& key, const wxString& szValue) { wxConfigPathChanger path(this, key); wxString strName = path.Name(); if ( strName.IsEmpty() ) { // setting the value of a group is an error wxASSERT_MSG( wxIsEmpty(szValue), wxT("can't set value of a group!") ); // ... except if it's empty in which case it's a way to force it's creation m_pCurrentGroup->SetDirty(); // this will add a line for this group if it didn't have it before (void)m_pCurrentGroup->GetGroupLine(); } else { // writing an entry // check that the name is reasonable if ( strName[0u] == wxCONFIG_IMMUTABLE_PREFIX ) { wxLogError(_("Config entry name cannot start with '%c'."), wxCONFIG_IMMUTABLE_PREFIX); return FALSE; } ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(strName); if ( pEntry == NULL ) pEntry = m_pCurrentGroup->AddEntry(strName); pEntry->SetValue(szValue); } return TRUE; }
static wxString wxDefaultFileSelector(bool load, const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent) { wxString prompt; wxString str; if (load) str = _("Load %s file"); else str = _("Save %s file"); prompt.Printf(str, what); wxString wild; const wxChar *ext = extension; if ( !wxIsEmpty(ext) ) { if ( *ext == wxT('.') ) ext++; wild.Printf(wxT("*.%s"), ext); } else // no extension specified { wild = wxFileSelectorDefaultWildcardStr; } return wxFileSelector(prompt, NULL, default_name, ext, wild, load ? (wxFD_OPEN | wxFD_FILE_MUST_EXIST) : wxFD_SAVE, parent); }
wxString wxGetOsDescription() { wxString str; OSVERSIONINFO info; wxZeroMemory(info); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if ( ::GetVersionEx(&info) ) { switch ( info.dwPlatformId ) { #ifdef VER_PLATFORM_WIN32_CE case VER_PLATFORM_WIN32_CE: str.Printf(_("Windows CE (%d.%d)"), info.dwMajorVersion, info.dwMinorVersion); break; #endif case VER_PLATFORM_WIN32s: str = _("Win32s on Windows 3.1"); break; case VER_PLATFORM_WIN32_WINDOWS: switch (info.dwMinorVersion) { case 0: if ( info.szCSDVersion[1] == 'B' || info.szCSDVersion[1] == 'C' ) { str = _("Windows 95 OSR2"); } else { str = _("Windows 95"); } break; case 10: if ( info.szCSDVersion[1] == 'B' || info.szCSDVersion[1] == 'C' ) { str = _("Windows 98 SE"); } else { str = _("Windows 98"); } break; case 90: str = _("Windows ME"); break; default: str.Printf(_("Windows 9x (%d.%d)"), info.dwMajorVersion, info.dwMinorVersion); break; } if ( !wxIsEmpty(info.szCSDVersion) ) { str << _T(" (") << info.szCSDVersion << _T(')'); } break; case VER_PLATFORM_WIN32_NT: switch ( info.dwMajorVersion ) { case 5: switch ( info.dwMinorVersion ) { case 0: str.Printf(_("Windows 2000 (build %lu"), info.dwBuildNumber); break; case 1: str.Printf(_("Windows XP (build %lu"), info.dwBuildNumber); break; case 2: str.Printf(_("Windows Server 2003 (build %lu"), info.dwBuildNumber); break; } break; case 6: if ( info.dwMinorVersion == 0 ) { str.Printf(_("Windows Vista (build %lu"), info.dwBuildNumber); } break; } if ( str.empty() ) { str.Printf(_("Windows NT %lu.%lu (build %lu"), info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber); } if ( !wxIsEmpty(info.szCSDVersion) ) { str << _T(", ") << info.szCSDVersion; } str << _T(')'); break; } } else { wxFAIL_MSG( _T("GetVersionEx() failed") ); // should never happen } return str; }
wxString wxGetOsDescription() { wxString str; const OSVERSIONINFOEX info = wxGetWindowsVersionInfo(); switch ( info.dwPlatformId ) { #ifdef VER_PLATFORM_WIN32_CE case VER_PLATFORM_WIN32_CE: str.Printf(_("Windows CE (%d.%d)"), info.dwMajorVersion, info.dwMinorVersion); break; #endif case VER_PLATFORM_WIN32s: str = _("Win32s on Windows 3.1"); break; case VER_PLATFORM_WIN32_WINDOWS: switch (info.dwMinorVersion) { case 0: if ( info.szCSDVersion[1] == 'B' || info.szCSDVersion[1] == 'C' ) { str = _("Windows 95 OSR2"); } else { str = _("Windows 95"); } break; case 10: if ( info.szCSDVersion[1] == 'B' || info.szCSDVersion[1] == 'C' ) { str = _("Windows 98 SE"); } else { str = _("Windows 98"); } break; case 90: str = _("Windows ME"); break; default: str.Printf(_("Windows 9x (%d.%d)"), info.dwMajorVersion, info.dwMinorVersion); break; } if ( !wxIsEmpty(info.szCSDVersion) ) { str << wxT(" (") << info.szCSDVersion << wxT(')'); } break; case VER_PLATFORM_WIN32_NT: switch ( info.dwMajorVersion ) { case 5: switch ( info.dwMinorVersion ) { case 0: str = _("Windows 2000"); break; case 2: // we can't distinguish between XP 64 and 2003 // as they both are 5.2, so examine the product // type to resolve this ambiguity if ( wxIsWindowsServer() == 1 ) { str = _("Windows Server 2003"); break; } //else: must be XP, fall through case 1: str = _("Windows XP"); break; } break; case 6: switch ( info.dwMinorVersion ) { case 0: str = wxIsWindowsServer() == 1 ? _("Windows Server 2008") : _("Windows Vista"); break; case 1: str = wxIsWindowsServer() == 1 ? _("Windows Server 2008 R2") : _("Windows 7"); break; case 2: str = wxIsWindowsServer() == 1 ? _("Windows Server 2012") : _("Windows 8"); break; case 3: str = wxIsWindowsServer() == 1 ? _("Windows Server 2012 R2") : _("Windows 8.1"); break; } break; case 10: str = wxIsWindowsServer() == 1 ? _("Windows Server 10") : _("Windows 10"); break; } if ( str.empty() ) { str.Printf(_("Windows NT %lu.%lu"), info.dwMajorVersion, info.dwMinorVersion); } str << wxT(" (") << wxString::Format(_("build %lu"), info.dwBuildNumber); if ( !wxIsEmpty(info.szCSDVersion) ) { str << wxT(", ") << info.szCSDVersion; } str << wxT(')'); if ( wxIsPlatform64Bit() ) str << _(", 64-bit edition"); break; } return str; }
wxString wxFileSelector(const wxChar *title, const wxChar *defaultDir, const wxChar *defaultFileName, const wxChar *defaultExtension, const wxChar *filter, int flags, wxWindow *parent, int x, int y) { // The defaultExtension, if non-NULL, is // appended to the filename if the user fails to type an extension. The new // implementation (taken from wxFileSelectorEx) appends the extension // automatically, by looking at the filter specification. In fact this // should be better than the native Microsoft implementation because // Windows only allows *one* default extension, whereas here we do the // right thing depending on the filter the user has chosen. // If there's a default extension specified but no filter, we create a // suitable filter. wxString filter2; if ( !wxIsEmpty(defaultExtension) && wxIsEmpty(filter) ) filter2 = wxString(wxT("*.")) + defaultExtension; else if ( !wxIsEmpty(filter) ) filter2 = filter; wxString defaultDirString; if (!wxIsEmpty(defaultDir)) defaultDirString = defaultDir; wxString defaultFilenameString; if (!wxIsEmpty(defaultFileName)) defaultFilenameString = defaultFileName; wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y)); // if filter is of form "All files (*)|*|..." set correct filter index if((wxStrlen(defaultExtension) != 0) && (filter2.Find(wxT('|')) != wxNOT_FOUND)) { int filterIndex = 0; wxArrayString descriptions, filters; // don't care about errors, handled already by wxFileDialog (void)wxParseCommonDialogsFilter(filter2, descriptions, filters); for (size_t n=0; n<filters.GetCount(); n++) { if (filters[n].Contains(defaultExtension)) { filterIndex = n; break; } } if (filterIndex > 0) fileDialog.SetFilterIndex(filterIndex); } wxString filename; if ( fileDialog.ShowModal() == wxID_OK ) { filename = fileDialog.GetPath(); } return filename; }