// Get Full RFC822 style email address bool wxGetEmailAddress(wxChar *address, int maxSize) { wxString email = wxGetEmailAddress(); if ( !email ) return false; wxStrlcpy(address, email.t_str(), maxSize); return true; }
bool wxTaskBarButtonImpl::InitOrUpdateThumbBarButtons() { THUMBBUTTON buttons[MAX_BUTTON_COUNT]; HRESULT hr; for ( size_t i = 0; i < MAX_BUTTON_COUNT; ++i ) { memset(&buttons[i], 0, sizeof buttons[i]); buttons[i].iId = i; buttons[i].dwFlags = THBF_HIDDEN; buttons[i].dwMask = static_cast<THUMBBUTTONMASK>(THB_FLAGS); } for ( size_t i = 0; i < m_thumbBarButtons.size(); ++i ) { buttons[i].hIcon = GetHiconOf(m_thumbBarButtons[i]->GetIcon()); buttons[i].dwFlags = GetNativeThumbButtonFlags(*m_thumbBarButtons[i]); buttons[i].dwMask = static_cast<THUMBBUTTONMASK>(THB_ICON | THB_FLAGS); wxString tooltip = m_thumbBarButtons[i]->GetTooltip(); if ( tooltip.empty() ) continue; // Truncate the tooltip if its length longer than szTip(THUMBBUTTON) // allowed length (260). tooltip.Truncate(260); wxStrlcpy(buttons[i].szTip, tooltip.t_str(), tooltip.length()); buttons[i].dwMask = static_cast<THUMBBUTTONMASK>(buttons[i].dwMask | THB_TOOLTIP); } if ( !m_hasInitThumbnailToolbar ) { hr = m_taskbarList->ThumbBarAddButtons(m_parent->GetHWND(), MAX_BUTTON_COUNT, buttons); if ( FAILED(hr) ) { wxLogApiError(wxT("ITaskbarList3::ThumbBarAddButtons"), hr); } m_hasInitThumbnailToolbar = true; } else { hr = m_taskbarList->ThumbBarUpdateButtons(m_parent->GetHWND(), MAX_BUTTON_COUNT, buttons); if ( FAILED(hr) ) { wxLogApiError(wxT("ITaskbarList3::ThumbBarUpdateButtons"), hr); } } return SUCCEEDED(hr); }
// returns %UserName%, $USER or just "user" // bool wxGetUserId(wxChar *buf, int n) { const wxChar *user = wxGetenv(wxT("UserName")); if (!user) user = wxGetenv(wxT("USER")); if (!user) user = wxT("user"); wxStrlcpy(buf, user, n); return true; }
// returns %ComputerName%, or $HOSTNAME, or "host" // bool wxGetHostName(wxChar *buf, int n) { const wxChar *host = wxGetenv(wxT("ComputerName")); if (!host) host = wxGetenv(wxT("HOSTNAME")); if (!host) host = wxT("host"); wxStrlcpy(buf, host, n); return true; }
bool wxGetUserId(wxChar *buf, int sz) { struct passwd *who; *buf = wxT('\0'); if ((who = getpwuid(getuid ())) != NULL) { wxStrlcpy (buf, wxSafeConvertMB2WX(who->pw_name), sz); return true; } return false; }
void wxFontEnumeratorHelper::DoEnumerate() { HDC hDC = ::GetDC(NULL); LOGFONT lf; lf.lfCharSet = (BYTE)m_charset; wxStrlcpy(lf.lfFaceName, m_facename.c_str(), WXSIZEOF(lf.lfFaceName)); lf.lfPitchAndFamily = 0; ::EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC)wxFontEnumeratorProc, (LPARAM)this, 0 /* reserved */) ; ::ReleaseDC(NULL, hDC); }
bool wxSockAddressImpl::SetPath(const wxString& path) { sockaddr_un * const addr = Get<sockaddr_un>(); if ( !addr ) return false; const wxScopedCharBuffer buf(path.utf8_str()); if ( strlen(buf) >= UNIX_PATH_MAX ) return false; wxStrlcpy(addr->sun_path, buf, UNIX_PATH_MAX); return true; }
// debugger helper: this function can be called from a debugger to show what // the date really is extern const char *wxDumpFont(const wxFont *font) { static char buf[256]; wxString s; s.Printf(wxS("%s-%d-%s-%.2f-%d"), font->GetFaceName(), font->GetNumericWeight(), font->GetStyle() == wxFONTSTYLE_NORMAL ? "regular" : "italic", font->GetFractionalPointSize(), font->GetEncoding()); wxStrlcpy(buf, s.mb_str(), WXSIZEOF(buf)); return buf; }
// Get full hostname (eg. DoDo.BSn-Germany.crg.de) bool wxGetHostName( wxChar* zBuf, int nMaxSize ) { if (!zBuf) return false; #if defined(wxUSE_NET_API) && wxUSE_NET_API char zServer[256]; char zComputer[256]; unsigned long ulLevel = 0; unsigned char* zBuffer = NULL; unsigned long ulBuffer = 256; unsigned long* pulTotalAvail = NULL; NetBios32GetInfo( (const unsigned char*)zServer ,(const unsigned char*)zComputer ,ulLevel ,zBuffer ,ulBuffer ,pulTotalAvail ); strcpy(zBuf, zServer); #else wxChar* zSysname; const wxChar* zDefaultHost = _T("noname"); if ((zSysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL && (zSysname = wxGetenv(_T("HOSTNAME"))) == NULL) { ::PrfQueryProfileString( HINI_PROFILE ,(PSZ)WX_SECTION ,(PSZ)eHOSTNAME ,(PSZ)zDefaultHost ,(void*)zBuf ,(ULONG)nMaxSize - 1 ); zBuf[nMaxSize] = _T('\0'); } else { wxStrlcpy(zBuf, zSysname, nMaxSize); } #endif return *zBuf ? true : false; }
// Operations bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) { // NB: we have to create the window lazily because of backward compatibility, // old applications may create a wxTaskBarIcon instance before wxApp // is initialized (as samples/taskbar used to do) if (!m_win) { m_win = new wxTaskBarIconWindow(this); } m_icon = icon; m_strTooltip = tooltip; NotifyIconData notifyData(GetHwndOf(m_win)); if (icon.IsOk()) { notifyData.uFlags |= NIF_ICON; notifyData.hIcon = GetHiconOf(icon); } // set NIF_TIP even for an empty tooltip: otherwise it would be impossible // to remove an existing tooltip using this function notifyData.uFlags |= NIF_TIP; if ( !tooltip.empty() ) { wxStrlcpy(notifyData.szTip, tooltip.t_str(), WXSIZEOF(notifyData.szTip)); } bool ok = Shell_NotifyIcon(m_iconAdded ? NIM_MODIFY : NIM_ADD, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("Shell_NotifyIcon(NIM_MODIFY/ADD)")); } if ( !m_iconAdded && ok ) m_iconAdded = true; return ok; }
bool wxTestFontEncoding(const wxNativeEncodingInfo& info) { // try to create such font LOGFONT lf; wxZeroMemory(lf); // all default values lf.lfCharSet = (BYTE)info.charset; wxStrlcpy(lf.lfFaceName, info.facename.c_str(), WXSIZEOF(lf.lfFaceName)); HFONT hfont = ::CreateFontIndirect(&lf); if ( !hfont ) { // no such font return false; } ::DeleteObject((HGDIOBJ)hfont); return true; }
bool wxGetUserName(wxChar *buf, int sz) { #ifdef HAVE_PW_GECOS struct passwd *who; *buf = wxT('\0'); if ((who = getpwuid (getuid ())) != NULL) { char *comma = strchr(who->pw_gecos, ','); if (comma) *comma = '\0'; // cut off non-name comment fields wxStrlcpy(buf, wxSafeConvertMB2WX(who->pw_gecos), sz); return true; } return false; #else // !HAVE_PW_GECOS return wxGetUserId(buf, sz); #endif // HAVE_PW_GECOS/!HAVE_PW_GECOS }
void wxFontEnumeratorHelper::DoEnumerate() { #ifndef __WXMICROWIN__ HDC hDC = ::GetDC(NULL); #ifdef __WXWINCE__ ::EnumFontFamilies(hDC, m_facename.empty() ? NULL : m_facename.wx_str(), (wxFONTENUMPROC)wxFontEnumeratorProc, (LPARAM)this) ; #else // __WIN32__ LOGFONT lf; lf.lfCharSet = (BYTE)m_charset; wxStrlcpy(lf.lfFaceName, m_facename.c_str(), WXSIZEOF(lf.lfFaceName)); lf.lfPitchAndFamily = 0; ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc, (LPARAM)this, 0 /* reserved */) ; #endif // Win32/CE ::ReleaseDC(NULL, hDC); #endif }
// Operations bool gcTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) { #ifdef WIN32 m_icon = icon; m_strTooltip = tooltip; NotifyIconData notifyData(GetHwndOf(m_win)); if (icon.Ok()) { notifyData.uFlags |= NIF_ICON; notifyData.hIcon = GetHiconOf(icon); } // set NIF_TIP even for an empty tooltip: otherwise it would be impossible // to remove an existing tooltip using this function notifyData.uFlags |= NIF_TIP; if ( !tooltip.empty() ) { wxStrlcpy(notifyData.szTip, tooltip.wx_str(), WXSIZEOF(notifyData.szTip)); } bool ok = wxShellNotifyIcon(m_iconAdded ? NIM_MODIFY : NIM_ADD, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY/ADD)")); } if ( !m_iconAdded && ok ) m_iconAdded = true; return ok; #else return wxTaskBarIcon::SetIcon(icon, tooltip); #endif }
// debugger helper: this function can be called from a debugger to show what // the date really is extern const char *wxDumpFont(const wxFont *font) { static char buf[256]; const wxFontWeight weight = font->GetWeight(); wxString s; s.Printf(wxS("%s-%s-%s-%d-%d"), font->GetFaceName(), weight == wxFONTWEIGHT_NORMAL ? wxT("normal") : weight == wxFONTWEIGHT_BOLD ? wxT("bold") : wxT("light"), font->GetStyle() == wxFONTSTYLE_NORMAL ? wxT("regular") : wxT("italic"), font->GetPointSize(), font->GetEncoding()); wxStrlcpy(buf, s.mb_str(), WXSIZEOF(buf)); return buf; }
// Get hostname only (without domain name) bool wxGetHostName(wxChar *buf, int maxSize) { #if defined(__WXWINCE__) // GetComputerName() is not supported but the name seems to be stored in // this location in the registry, at least for PPC2003 and WM5 wxString hostName; wxRegKey regKey(wxRegKey::HKLM, wxT("Ident")); if ( !regKey.HasValue(wxT("Name")) || !regKey.QueryValue(wxT("Name"), hostName) ) return false; wxStrlcpy(buf, hostName.t_str(), maxSize); #else // !__WXWINCE__ DWORD nSize = maxSize; if ( !::GetComputerName(buf, &nSize) ) { wxLogLastError(wxT("GetComputerName")); return false; } #endif // __WXWINCE__/!__WXWINCE__ return true; }
// get full hostname (with domain name if possible) bool wxGetFullHostName(wxChar *buf, int maxSize) { #if wxUSE_DYNLIB_CLASS && wxUSE_SOCKETS // TODO should use GetComputerNameEx() when available // we don't want to always link with Winsock DLL as we might not use it at // all, so load it dynamically here if needed (and don't complain if it is // missing, we handle this) wxLogNull noLog; wxDynamicLibrary dllWinsock(wxT("ws2_32.dll"), wxDL_VERBATIM); if ( dllWinsock.IsLoaded() ) { typedef int (PASCAL *WSAStartup_t)(WORD, WSADATA *); typedef int (PASCAL *gethostname_t)(char *, int); typedef hostent* (PASCAL *gethostbyname_t)(const char *); typedef hostent* (PASCAL *gethostbyaddr_t)(const char *, int , int); typedef int (PASCAL *WSACleanup_t)(void); #define LOAD_WINSOCK_FUNC(func) \ func ## _t \ pfn ## func = (func ## _t)dllWinsock.GetSymbol(wxT(#func)) LOAD_WINSOCK_FUNC(WSAStartup); WSADATA wsa; if ( pfnWSAStartup && pfnWSAStartup(MAKEWORD(1, 1), &wsa) == 0 ) { LOAD_WINSOCK_FUNC(gethostname); wxString host; if ( pfngethostname ) { char bufA[256]; if ( pfngethostname(bufA, WXSIZEOF(bufA)) == 0 ) { // gethostname() won't usually include the DNS domain name, // for this we need to work a bit more if ( !strchr(bufA, '.') ) { LOAD_WINSOCK_FUNC(gethostbyname); struct hostent *pHostEnt = pfngethostbyname ? pfngethostbyname(bufA) : NULL; if ( pHostEnt ) { // Windows will use DNS internally now LOAD_WINSOCK_FUNC(gethostbyaddr); pHostEnt = pfngethostbyaddr ? pfngethostbyaddr(pHostEnt->h_addr, 4, AF_INET) : NULL; } if ( pHostEnt ) { host = pHostEnt->h_name; } } } } LOAD_WINSOCK_FUNC(WSACleanup); if ( pfnWSACleanup ) pfnWSACleanup(); if ( !host.empty() ) { wxStrlcpy(buf, host.c_str(), maxSize); return true; } } } #endif // wxUSE_DYNLIB_CLASS && wxUSE_SOCKETS return wxGetHostName(buf, maxSize); }
bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data ) { WinPrinter printer; LPTSTR szPrinterName = wxMSW_CONV_LPTSTR(data.GetPrinterName()); if (!m_devMode) InitializeDevMode(data.GetPrinterName(), &printer); HGLOBAL hDevMode = static_cast<HGLOBAL>(m_devMode); if ( hDevMode ) { GlobalPtrLock lockDevMode(hDevMode); DEVMODE * const devMode = static_cast<DEVMODE *>(lockDevMode.Get()); //// Orientation devMode->dmOrientation = (short)data.GetOrientation(); //// Collation devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); devMode->dmFields |= DM_COLLATE; //// Number of copies devMode->dmCopies = (short)data.GetNoCopies(); devMode->dmFields |= DM_COPIES; //// Printer name wxString name = data.GetPrinterName(); if (!name.empty()) { // NB: the cast is needed in the ANSI build, strangely enough // dmDeviceName is BYTE[] and not char[] there wxStrlcpy(reinterpret_cast<wxChar *>(devMode->dmDeviceName), name.t_str(), WXSIZEOF(devMode->dmDeviceName)); } //// Colour if (data.GetColour()) devMode->dmColor = DMCOLOR_COLOR; else devMode->dmColor = DMCOLOR_MONOCHROME; devMode->dmFields |= DM_COLOR; //// Paper size // Paper id has priority over paper size. If id is specified, then size // is ignored (as it can be filled in even for standard paper sizes) wxPrintPaperType *paperType = NULL; const wxPaperSize paperId = data.GetPaperId(); if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase ) { paperType = wxThePrintPaperDatabase->FindPaperType(paperId); } if ( paperType ) { devMode->dmPaperSize = (short)paperType->GetPlatformId(); devMode->dmFields |= DM_PAPERSIZE; } else // custom (or no) paper size { const wxSize paperSize = data.GetPaperSize(); if ( paperSize != wxDefaultSize ) { // Fall back on specifying the paper size explicitly if(m_customWindowsPaperId != 0) devMode->dmPaperSize = m_customWindowsPaperId; else devMode->dmPaperSize = DMPAPER_USER; devMode->dmPaperWidth = (short)(paperSize.x * 10); devMode->dmPaperLength = (short)(paperSize.y * 10); devMode->dmFields |= DM_PAPERWIDTH; devMode->dmFields |= DM_PAPERLENGTH; // A printer driver may or may not also want DM_PAPERSIZE to // be specified. Also, if the printer driver doesn't implement the DMPAPER_USER // size, then this won't work, and even if you found the correct id by // enumerating the driver's paper sizes, it probably won't change the actual size, // it'll just select that custom paper type with its own current setting. // For a discussion on this, see http://www.codeguru.com/forum/showthread.php?threadid=458617 // Although m_customWindowsPaperId is intended to work around this, it's // unclear how it can help you set the custom paper size programmatically. } //else: neither paper type nor size specified, don't fill DEVMODE // at all so that the system defaults are used } //// Duplex short duplex; switch (data.GetDuplex()) { case wxDUPLEX_HORIZONTAL: duplex = DMDUP_HORIZONTAL; break; case wxDUPLEX_VERTICAL: duplex = DMDUP_VERTICAL; break; default: // in fact case wxDUPLEX_SIMPLEX: duplex = DMDUP_SIMPLEX; break; } devMode->dmDuplex = duplex; devMode->dmFields |= DM_DUPLEX; //// Quality short quality; switch (data.GetQuality()) { case wxPRINT_QUALITY_MEDIUM: quality = DMRES_MEDIUM; break; case wxPRINT_QUALITY_LOW: quality = DMRES_LOW; break; case wxPRINT_QUALITY_DRAFT: quality = DMRES_DRAFT; break; case wxPRINT_QUALITY_HIGH: quality = DMRES_HIGH; break; default: quality = (short)data.GetQuality(); devMode->dmYResolution = quality; devMode->dmFields |= DM_YRESOLUTION; break; } devMode->dmPrintQuality = quality; devMode->dmFields |= DM_PRINTQUALITY; if (data.GetPrivDataLen() > 0) { memcpy( (char *)devMode+devMode->dmSize, data.GetPrivData(), data.GetPrivDataLen() ); devMode->dmDriverExtra = (WXWORD)data.GetPrivDataLen(); } if (data.GetBin() != wxPRINTBIN_DEFAULT) { switch (data.GetBin()) { case wxPRINTBIN_ONLYONE: devMode->dmDefaultSource = DMBIN_ONLYONE; break; case wxPRINTBIN_LOWER: devMode->dmDefaultSource = DMBIN_LOWER; break; case wxPRINTBIN_MIDDLE: devMode->dmDefaultSource = DMBIN_MIDDLE; break; case wxPRINTBIN_MANUAL: devMode->dmDefaultSource = DMBIN_MANUAL; break; case wxPRINTBIN_ENVELOPE: devMode->dmDefaultSource = DMBIN_ENVELOPE; break; case wxPRINTBIN_ENVMANUAL: devMode->dmDefaultSource = DMBIN_ENVMANUAL; break; case wxPRINTBIN_AUTO: devMode->dmDefaultSource = DMBIN_AUTO; break; case wxPRINTBIN_TRACTOR: devMode->dmDefaultSource = DMBIN_TRACTOR; break; case wxPRINTBIN_SMALLFMT: devMode->dmDefaultSource = DMBIN_SMALLFMT; break; case wxPRINTBIN_LARGEFMT: devMode->dmDefaultSource = DMBIN_LARGEFMT; break; case wxPRINTBIN_LARGECAPACITY: devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break; case wxPRINTBIN_CASSETTE: devMode->dmDefaultSource = DMBIN_CASSETTE; break; case wxPRINTBIN_FORMSOURCE: devMode->dmDefaultSource = DMBIN_FORMSOURCE; break; default: devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER); // 256 + data.GetBin() - 14 = 242 + data.GetBin() break; } devMode->dmFields |= DM_DEFAULTSOURCE; } if (data.GetMedia() != wxPRINTMEDIA_DEFAULT) { devMode->dmMediaType = data.GetMedia(); devMode->dmFields |= DM_MEDIATYPE; } if( printer ) { // Step 3: // Merge the new settings with the old. // This gives the driver an opportunity to update any private // portions of the DevMode structure. DocumentProperties( NULL, printer, szPrinterName, (LPDEVMODE)hDevMode, // Reuse our buffer for output. (LPDEVMODE)hDevMode, // Pass the driver our changes DM_IN_BUFFER | // Commands to Merge our changes and DM_OUT_BUFFER ); // write the result. } } if ( m_devNames ) { ::GlobalFree(static_cast<HGLOBAL>(m_devNames)); } // TODO: I hope it's OK to pass some empty strings to DEVNAMES. m_devNames = wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString); return true; }
int wxFileDialog::ShowModal() { HWND hWnd = 0; if (m_parent) hWnd = (HWND) m_parent->GetHWND(); if (!hWnd && wxTheApp->GetTopWindow()) hWnd = (HWND) wxTheApp->GetTopWindow()->GetHWND(); static wxChar fileNameBuffer [ wxMAXPATH ]; // the file-name wxChar titleBuffer [ wxMAXFILE+1+wxMAXEXT ]; // the file-name, without path *fileNameBuffer = wxT('\0'); *titleBuffer = wxT('\0'); long msw_flags = OFN_HIDEREADONLY; if ( HasFdFlag(wxFD_FILE_MUST_EXIST) ) msw_flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; /* If the window has been moved the programmer is probably trying to center or position it. Thus we set the callback or hook function so that we can actually adjust the position. Without moving or centering the dlg, it will just stay in the upper left of the frame, it does not center automatically. */ if (m_bMovedWindow || HasExtraControlCreator()) // we need these flags. { msw_flags |= OFN_EXPLORER|OFN_ENABLEHOOK; #ifndef __WXWINCE__ msw_flags |= OFN_ENABLESIZING; #endif } if ( HasFdFlag(wxFD_MULTIPLE) ) { // OFN_EXPLORER must always be specified with OFN_ALLOWMULTISELECT msw_flags |= OFN_EXPLORER | OFN_ALLOWMULTISELECT; } // if wxFD_CHANGE_DIR flag is not given we shouldn't change the CWD which the // standard dialog does by default (notice that under NT it does it anyhow, // OFN_NOCHANGEDIR or not, see below) if ( !HasFdFlag(wxFD_CHANGE_DIR) ) { msw_flags |= OFN_NOCHANGEDIR; } if ( HasFdFlag(wxFD_OVERWRITE_PROMPT) ) { msw_flags |= OFN_OVERWRITEPROMPT; } wxOPENFILENAME of; wxZeroMemory(of); of.lStructSize = gs_ofStructSize; of.hwndOwner = hWnd; of.lpstrTitle = m_message.wx_str(); of.lpstrFileTitle = titleBuffer; of.nMaxFileTitle = wxMAXFILE + 1 + wxMAXEXT; #ifndef __WXWINCE__ GlobalPtr hgbl; if ( HasExtraControlCreator() ) { msw_flags |= OFN_ENABLETEMPLATEHANDLE; hgbl.Init(256, GMEM_ZEROINIT); GlobalPtrLock hgblLock(hgbl); LPDLGTEMPLATE lpdt = static_cast<LPDLGTEMPLATE>(hgblLock.Get()); // Define a dialog box. lpdt->style = DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS; lpdt->cdit = 0; // Number of controls lpdt->x = 0; lpdt->y = 0; // convert the size of the extra controls to the dialog units const wxSize extraSize = GetExtraControlSize(); const LONG baseUnits = ::GetDialogBaseUnits(); lpdt->cx = ::MulDiv(extraSize.x, 4, LOWORD(baseUnits)); lpdt->cy = ::MulDiv(extraSize.y, 8, HIWORD(baseUnits)); // after the DLGTEMPLATE there are 3 additional WORDs for dialog menu, // class and title, all three set to zeros. of.hInstance = (HINSTANCE)lpdt; } #endif // __WXWINCE__ // Convert forward slashes to backslashes (file selector doesn't like // forward slashes) and also squeeze multiple consecutive slashes into one // as it doesn't like two backslashes in a row neither wxString dir; size_t i, len = m_dir.length(); dir.reserve(len); for ( i = 0; i < len; i++ ) { wxChar ch = m_dir[i]; switch ( ch ) { case wxT('/'): // convert to backslash ch = wxT('\\'); // fall through case wxT('\\'): while ( i < len - 1 ) { wxChar chNext = m_dir[i + 1]; if ( chNext != wxT('\\') && chNext != wxT('/') ) break; // ignore the next one, unless it is at the start of a UNC path if (i > 0) i++; else break; } // fall through default: // normal char dir += ch; } } of.lpstrInitialDir = dir.c_str(); of.Flags = msw_flags; of.lpfnHook = wxFileDialogHookFunction; of.lCustData = (LPARAM)this; wxArrayString wildDescriptions, wildFilters; size_t items = wxParseCommonDialogsFilter(m_wildCard, wildDescriptions, wildFilters); wxASSERT_MSG( items > 0 , wxT("empty wildcard list") ); wxString filterBuffer; for (i = 0; i < items ; i++) { filterBuffer += wildDescriptions[i]; filterBuffer += wxT("|"); filterBuffer += wildFilters[i]; filterBuffer += wxT("|"); } // Replace | with \0 for (i = 0; i < filterBuffer.length(); i++ ) { if ( filterBuffer.GetChar(i) == wxT('|') ) { filterBuffer[i] = wxT('\0'); } } of.lpstrFilter = (LPTSTR)filterBuffer.wx_str(); of.nFilterIndex = m_filterIndex + 1; //=== Setting defaultFileName >>========================================= wxStrlcpy(fileNameBuffer, m_fileName.c_str(), WXSIZEOF(fileNameBuffer)); of.lpstrFile = fileNameBuffer; // holds returned filename of.nMaxFile = wxMAXPATH; // we must set the default extension because otherwise Windows would check // for the existing of a wrong file with wxFD_OVERWRITE_PROMPT (i.e. if the // user types "foo" and the default extension is ".bar" we should force it // to check for "foo.bar" existence and not "foo") wxString defextBuffer; // we need it to be alive until GetSaveFileName()! if (HasFdFlag(wxFD_SAVE)) { const wxChar* extension = filterBuffer.wx_str(); int maxFilter = (int)(of.nFilterIndex*2L) - 1; for( int i = 0; i < maxFilter; i++ ) // get extension extension = extension + wxStrlen( extension ) + 1; // use dummy name a to avoid assert in AppendExtension defextBuffer = AppendExtension(wxT("a"), extension); if (defextBuffer.StartsWith(wxT("a."))) { defextBuffer = defextBuffer.Mid(2); // remove "a." of.lpstrDefExt = defextBuffer.c_str(); } } // store off before the standard windows dialog can possibly change it const wxString cwdOrig = wxGetCwd(); //== Execute FileDialog >>================================================= if ( !ShowCommFileDialog(&of, m_windowStyle) ) return wxID_CANCEL; // GetOpenFileName will always change the current working directory on // (according to MSDN) "Windows NT 4.0/2000/XP" because the flag // OFN_NOCHANGEDIR has no effect. If the user did not specify // wxFD_CHANGE_DIR let's restore the current working directory to what it // was before the dialog was shown. if ( msw_flags & OFN_NOCHANGEDIR ) { wxSetWorkingDirectory(cwdOrig); } m_fileNames.Empty(); if ( ( HasFdFlag(wxFD_MULTIPLE) ) && #if defined(OFN_EXPLORER) ( fileNameBuffer[of.nFileOffset-1] == wxT('\0') ) #else ( fileNameBuffer[of.nFileOffset-1] == wxT(' ') ) #endif // OFN_EXPLORER ) { #if defined(OFN_EXPLORER) m_dir = fileNameBuffer; i = of.nFileOffset; m_fileName = &fileNameBuffer[i]; m_fileNames.Add(m_fileName); i += m_fileName.length() + 1; while (fileNameBuffer[i] != wxT('\0')) { m_fileNames.Add(&fileNameBuffer[i]); i += wxStrlen(&fileNameBuffer[i]) + 1; } #else wxStringTokenizer toke(fileNameBuffer, wxT(" \t\r\n")); m_dir = toke.GetNextToken(); m_fileName = toke.GetNextToken(); m_fileNames.Add(m_fileName); while (toke.HasMoreTokens()) m_fileNames.Add(toke.GetNextToken()); #endif // OFN_EXPLORER wxString dir(m_dir); if ( m_dir.Last() != wxT('\\') ) dir += wxT('\\'); m_path = dir + m_fileName; m_filterIndex = (int)of.nFilterIndex - 1; } else { //=== Adding the correct extension >>================================= m_filterIndex = (int)of.nFilterIndex - 1; if ( !of.nFileExtension || (of.nFileExtension && fileNameBuffer[of.nFileExtension] == wxT('\0')) ) { // User has typed a filename without an extension: const wxChar* extension = filterBuffer.wx_str(); int maxFilter = (int)(of.nFilterIndex*2L) - 1; for( int i = 0; i < maxFilter; i++ ) // get extension extension = extension + wxStrlen( extension ) + 1; m_fileName = AppendExtension(fileNameBuffer, extension); wxStrlcpy(fileNameBuffer, m_fileName.c_str(), WXSIZEOF(fileNameBuffer)); } m_path = fileNameBuffer; m_fileName = wxFileNameFromPath(fileNameBuffer); m_fileNames.Add(m_fileName); m_dir = wxPathOnly(fileNameBuffer); } return wxID_OK; }
/* static */ void wxCrashReport::SetFileName(const wxString& filename) { wxStrlcpy(gs_reportFilename, filename.wx_str(), WXSIZEOF(gs_reportFilename)); }
// Get user name e.g. Julian Smart bool wxGetUserName(wxChar *buf, int maxSize) { wxCHECK_MSG( buf && ( maxSize > 0 ), false, wxT("empty buffer in wxGetUserName") ); #if defined(__WXWINCE__) && wxUSE_REGKEY wxLogNull noLog; wxRegKey key(wxRegKey::HKCU, wxT("ControlPanel\\Owner")); if(!key.Open(wxRegKey::Read)) return false; wxString name; if(!key.QueryValue(wxT("Owner"),name)) return false; wxStrlcpy(buf, name.c_str(), maxSize); return true; #elif defined(USE_NET_API) CHAR szUserName[256]; if ( !wxGetUserId(szUserName, WXSIZEOF(szUserName)) ) return false; // TODO how to get the domain name? CHAR *szDomain = ""; // the code is based on the MSDN example (also see KB article Q119670) WCHAR wszUserName[256]; // Unicode user name WCHAR wszDomain[256]; LPBYTE ComputerName; USER_INFO_2 *ui2; // User structure // Convert ANSI user name and domain to Unicode MultiByteToWideChar( CP_ACP, 0, szUserName, strlen(szUserName)+1, wszUserName, WXSIZEOF(wszUserName) ); MultiByteToWideChar( CP_ACP, 0, szDomain, strlen(szDomain)+1, wszDomain, WXSIZEOF(wszDomain) ); // Get the computer name of a DC for the domain. if ( NetGetDCName( NULL, wszDomain, &ComputerName ) != NERR_Success ) { wxLogError(wxT("Cannot find domain controller")); goto error; } // Look up the user on the DC NET_API_STATUS status = NetUserGetInfo( (LPWSTR)ComputerName, (LPWSTR)&wszUserName, 2, // level - we want USER_INFO_2 (LPBYTE *) &ui2 ); switch ( status ) { case NERR_Success: // ok break; case NERR_InvalidComputer: wxLogError(wxT("Invalid domain controller name.")); goto error; case NERR_UserNotFound: wxLogError(wxT("Invalid user name '%s'."), szUserName); goto error; default: wxLogSysError(wxT("Can't get information about user")); goto error; } // Convert the Unicode full name to ANSI WideCharToMultiByte( CP_ACP, 0, ui2->usri2_full_name, -1, buf, maxSize, NULL, NULL ); return true; error: wxLogError(wxT("Couldn't look up full user name.")); return false; #else // !USE_NET_API // Could use NIS, MS-Mail or other site specific programs // Use wxWidgets configuration data bool ok = GetProfileString(WX_SECTION, eUSERNAME, wxEmptyString, buf, maxSize - 1) != 0; if ( !ok ) { ok = wxGetUserId(buf, maxSize); } if ( !ok ) { wxStrlcpy(buf, wxT("Unknown User"), maxSize); } return true; #endif // Win32/16 }
bool gcTaskBarIcon::ShowBalloon(const wxString& title, const wxString& text, unsigned msec, int flags) { #if defined(WIN32) wxCHECK_MSG( m_iconAdded, false, _T("can't be used before the icon is created") ); const HWND hwnd = GetHwndOf(m_win); // we need to enable version 5.0 behaviour to receive notifications about // the balloon disappearance NotifyIconData notifyData(hwnd); notifyData.uFlags = 0; notifyData.uVersion = 3 /* NOTIFYICON_VERSION for Windows XP */; if ( !wxShellNotifyIcon(NIM_SETVERSION, ¬ifyData) ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_SETVERSION)")); } // do show the balloon now notifyData = NotifyIconData(hwnd); notifyData.uFlags |= NIF_INFO; notifyData.uTimeout = msec; wxStrlcpy(notifyData.szInfo, text.wx_str(), WXSIZEOF(notifyData.szInfo)); wxStrlcpy(notifyData.szInfoTitle, title.wx_str(), WXSIZEOF(notifyData.szInfoTitle)); if ( flags & wxICON_INFORMATION ) notifyData.dwInfoFlags |= NIIF_INFO; else if ( flags & wxICON_WARNING ) notifyData.dwInfoFlags |= NIIF_WARNING; else if ( flags & wxICON_ERROR ) notifyData.dwInfoFlags |= NIIF_ERROR; bool ok = wxShellNotifyIcon(NIM_MODIFY, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY)")); } return ok; #elif defined(NIX) const char* icon = NULL; if ( flags & wxICON_INFORMATION ) icon = "dialog-information"; else if ( flags & wxICON_WARNING ) icon = "dialog-warning"; else if ( flags & wxICON_ERROR ) icon = "dialog-error"; NotifyNotification* notification = notify_notification_new( title.c_str(), text.c_str(), icon); notify_notification_show(notification, NULL); return true; #else return false; #endif }
// 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, wxS("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 ) { wxStrlcpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf)); 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] == wxS('\r') ) s_szBuf[len - 2] = wxS('\0'); } } else #endif // !__SMARTPHONE__ { s_szBuf[0] = wxS('\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__ }
void wxOS2SelectMatchingFontByName( PFATTRS pFattrs , PFACENAMEDESC pFaceName , PFONTMETRICS pFM , int nNumFonts , const wxFont* pFont ) { int i; int nPointSize; int nIs; int nMinDiff0; int anDiff[16]; int anMinDiff[16]; int nIndex = 0; wxChar zFontFaceName[FACESIZE]; wxString sFaceName; USHORT usWeightClass; int fsSelection = 0; nMinDiff0 = 0xf000; for(i = 0;i < 16; i++) anMinDiff[i] = nMinDiff0; switch (pFont->GetFamily()) { case wxSCRIPT: sFaceName = wxT("Tms Rmn"); break; case wxDECORATIVE: sFaceName = wxT("WarpSans"); break; case wxROMAN: sFaceName = wxT("Tms Rmn"); break; case wxTELETYPE: sFaceName = wxT("Courier") ; break; case wxMODERN: sFaceName = wxT("System VIO") ; break; case wxSWISS: sFaceName = wxT("Helv") ; break; case wxDEFAULT: default: sFaceName = wxT("System VIO") ; } switch (pFont->GetWeight()) { default: wxFAIL_MSG(wxT("unknown font weight")); // fall through usWeightClass = FWEIGHT_DONT_CARE; break; case wxNORMAL: usWeightClass = FWEIGHT_NORMAL; break; case wxLIGHT: usWeightClass = FWEIGHT_LIGHT; break; case wxBOLD: usWeightClass = FWEIGHT_BOLD; break; case wxFONTWEIGHT_MAX: usWeightClass = FWEIGHT_ULTRA_BOLD; break; } pFaceName->usWeightClass = usWeightClass; switch (pFont->GetStyle()) { case wxITALIC: case wxSLANT: fsSelection = FM_SEL_ITALIC; pFaceName->flOptions = FTYPE_ITALIC; break; default: wxFAIL_MSG(wxT("unknown font slant")); // fall through case wxNORMAL: fsSelection = 0; break; } wxStrlcpy(zFontFaceName, sFaceName.c_str(), WXSIZEOF(zFontFaceName)); nPointSize = pFont->GetPointSize(); // // Matching logic to find the right FM struct // nIndex = 0; for(i = 0, nIs = 0; i < nNumFonts; i++) { anDiff[0] = wxGpiStrcmp((wxChar*)pFM[i].szFacename, zFontFaceName); anDiff[1] = abs(pFM[i].lEmHeight - nPointSize); anDiff[2] = abs(pFM[i].usWeightClass - usWeightClass); anDiff[3] = abs((pFM[i].fsSelection & 0x2f) - fsSelection); if(anDiff[0] == 0) { if( (nIs & 0x01) == 0) { nIs = 1; nIndex = i; anMinDiff[1] = anDiff[1]; anMinDiff[2] = anDiff[2]; anMinDiff[3] = anDiff[3]; } else if(anDiff[3] < anMinDiff[3]) { nIndex = i; anMinDiff[3] = anDiff[3]; } else if(anDiff[2] < anMinDiff[2]) { nIndex = i; anMinDiff[2] = anDiff[2]; } else if(anDiff[1] < anMinDiff[1]) { nIndex = i; anMinDiff[1] = anDiff[1]; } anMinDiff[0] = 0; } else if(anDiff[0] < anMinDiff[0]) { nIs = 2; nIndex = i; anMinDiff[3] = anDiff[3]; anMinDiff[2] = anDiff[2]; anMinDiff[1] = anDiff[1]; anMinDiff[0] = anDiff[0]; } else if(anDiff[0] == anMinDiff[0]) { if(anDiff[3] < anMinDiff[3]) { nIndex = i; anMinDiff[3] = anDiff[3]; nIs = 2; } else if(anDiff[2] < anMinDiff[2]) { nIndex = i; anMinDiff[2] = anDiff[2]; nIs = 2; } else if(anDiff[1] < anMinDiff[1]) { nIndex = i; anMinDiff[1] = anDiff[1]; nIs = 2; } } } // // Fill in the FATTRS with the best match from FONTMETRICS // pFattrs->usRecordLength = sizeof(FATTRS); // Sets size of structure pFattrs->lMatch = pFM[nIndex].lMatch; // Force match pFattrs->idRegistry = 0; pFattrs->usCodePage = 0; pFattrs->fsFontUse = 0; pFattrs->fsType = 0; pFattrs->lMaxBaselineExt = 0; pFattrs->lAveCharWidth = 0; wxStrcpy((wxChar*)pFattrs->szFacename, (wxChar*)pFM[nIndex].szFacename); if (pFont->GetWeight() == wxNORMAL) pFattrs->fsSelection = 0; else pFattrs->fsSelection = FATTR_SEL_BOLD; if (pFont->GetStyle() == wxITALIC || pFont->GetStyle() == wxSLANT) pFattrs->fsSelection |= FATTR_SEL_ITALIC; if (pFont->GetUnderlined()) pFattrs->fsSelection |= FATTR_SEL_UNDERSCORE; } // end of wxOS2SelectMatchingFontByName