X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6aa68c25a4599f20186dca3604eee1597ddc7fc4..8394f0a06bb5c84fbde2e2449e7bf72a1347fb66:/src/common/utilscmn.cpp?ds=sidebyside diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 05f0ebd938..48cda637a5 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -72,7 +72,6 @@ #include "wx/colordlg.h" #include "wx/fontdlg.h" #include "wx/notebook.h" - #include "wx/frame.h" #include "wx/statusbr.h" #endif // wxUSE_GUI @@ -97,6 +96,7 @@ #if defined(__WXMSW__) #include "wx/msw/private.h" #include "wx/msw/registry.h" + #include // needed for SHELLEXECUTEINFO #endif #if wxUSE_BASE @@ -287,22 +287,20 @@ wxString wxGetDataDir() return dir; } -int wxGetOsVersion(int *verMaj, int *verMin) +bool wxIsPlatformLittleEndian() { - // we want this function to work even if there is no wxApp - wxConsoleAppTraits traitsConsole; - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; - if ( ! traits ) - traits = &traitsConsole; + // Are we little or big endian? This method is from Harbison & Steele. + union + { + long l; + char c[sizeof(long)]; + } u; + u.l = 1; - wxToolkitInfo& info = traits->GetToolkitInfo(); - if ( verMaj ) - *verMaj = info.versionMajor; - if ( verMin ) - *verMin = info.versionMinor; - return info.os; + return u.c[0] == 1; } + /* * Class to make it easier to specify platform-dependent values */ @@ -442,11 +440,11 @@ void wxPlatform::ClearPlatforms() bool wxPlatform::Is(int platform) { #ifdef __WXMSW__ - if (platform == wxMSW) + if (platform == wxOS_WINDOWS) return true; #endif #ifdef __WXWINCE__ - if (platform == wxWinCE) + if (platform == wxOS_WINDOWS_CE) return true; #endif #if defined(__WXWINCE__) && defined(__POCKETPC__) @@ -458,31 +456,31 @@ bool wxPlatform::Is(int platform) return true; #endif #ifdef __WXGTK__ - if (platform == wxGTK) + if (platform == wxPORT_GTK) return true; #endif #ifdef __WXMAC__ - if (platform == wxMac) + if (platform == wxPORT_MAC) return true; #endif #ifdef __WXX11__ - if (platform == wxX11) + if (platform == wxPORT_X11) return true; #endif #ifdef __UNIX__ - if (platform == wxUnix) + if (platform == wxOS_UNIX) return true; #endif #ifdef __WXMGL__ - if (platform == wxMGL) + if (platform == wxPORT_MGL) return true; #endif #ifdef __WXOS2__ - if (platform == wxOS2) + if (platform == wxPORT_OS2) return true; #endif #ifdef __WXCOCOA__ - if (platform == wxCocoa) + if (platform == wxPORT_MAC) return true; #endif @@ -819,7 +817,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags) { ConstStr255Param hint = 0; startSel = 0; - endSel = url.Length(); + endSel = url.length(); err = ICLaunchURL(inst, hint, url.fn_str(), endSel, &startSel, &endSel); if (err != noErr) wxLogDebug(wxT("ICLaunchURL error %d"), (int) err); @@ -914,15 +912,18 @@ wxRegisterId (long id) wxCurrentId = id + 1; } -#if wxUSE_MENUS - // ---------------------------------------------------------------------------- // Menu accelerators related functions // ---------------------------------------------------------------------------- wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out) { +#if wxUSE_MENUS wxString s = wxMenuItem::GetLabelFromText(in); +#else + wxString str(in); + wxString s = wxStripMenuCodes(str); +#endif // wxUSE_MENUS if ( out ) { // go smash their buffer if it's not big enough - I love char * params @@ -938,8 +939,10 @@ wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out) return out; } -wxString wxStripMenuCodes(const wxString& in) +wxString wxStripMenuCodes(const wxString& in, int flags) { + wxASSERT_MSG( flags, _T("this is useless to call without any flags") ); + wxString out; size_t len = in.length(); @@ -948,7 +951,7 @@ wxString wxStripMenuCodes(const wxString& in) for ( size_t n = 0; n < len; n++ ) { wxChar ch = in[n]; - if ( ch == _T('&') ) + if ( (flags & wxStrip_Mnemonics) && ch == _T('&') ) { // skip it, it is used to introduce the accel char (or to quote // itself in which case it should still be skipped): note that it @@ -963,7 +966,7 @@ wxString wxStripMenuCodes(const wxString& in) ch = in[n]; } } - else if ( ch == _T('\t') ) + else if ( (flags & wxStrip_Accel) && ch == _T('\t') ) { // everything after TAB is accel string, exit the loop break; @@ -975,8 +978,6 @@ wxString wxStripMenuCodes(const wxString& in) return out; } -#endif // wxUSE_MENUS - // ---------------------------------------------------------------------------- // Window search functions // ---------------------------------------------------------------------------- @@ -1011,12 +1012,12 @@ int wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& itemString) { #if wxUSE_MENUS - wxMenuBar *menuBar = frame->GetMenuBar (); - if ( menuBar ) - return menuBar->FindMenuItem (menuString, itemString); + wxMenuBar *menuBar = frame->GetMenuBar (); + if ( menuBar ) + return menuBar->FindMenuItem (menuString, itemString); #endif // wxUSE_MENUS - return wxNOT_FOUND; + return wxNOT_FOUND; } // Try to find the deepest child that contains 'pt'. @@ -1058,7 +1059,7 @@ wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt) wxPoint pos = win->GetPosition(); wxSize sz = win->GetSize(); - if (win->GetParent()) + if ( !win->IsTopLevel() && win->GetParent() ) { pos = win->GetParent()->ClientToScreen(pos); } @@ -1066,8 +1067,8 @@ wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt) wxRect rect(pos, sz); if (rect.Inside(pt)) return win; - else - return NULL; + + return NULL; } wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt) @@ -1193,7 +1194,7 @@ wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit, const wx wxColour colRet; wxColourDialog dialog(parent, &data); - if (!caption.IsEmpty()) + if (!caption.empty()) dialog.SetTitle(caption); if ( dialog.ShowModal() == wxID_OK ) { @@ -1218,7 +1219,7 @@ wxFont wxGetFontFromUser(wxWindow *parent, const wxFont& fontInit, const wxStrin wxFont fontRet; wxFontDialog dialog(parent, data); - if (!caption.IsEmpty()) + if (!caption.empty()) dialog.SetTitle(caption); if ( dialog.ShowModal() == wxID_OK ) {