#include "wx/config.h"
#if defined(__WXWINCE__) && wxUSE_DATETIME
-#include "wx/datetime.h"
+ #include "wx/datetime.h"
#endif
#include <ctype.h>
#include "wx/statusbr.h"
#endif // wxUSE_GUI
+#ifndef __WXPALMOS5__
#ifndef __WXWINCE__
-#include <time.h>
+ #include <time.h>
#else
-#include "wx/msw/wince/time.h"
+ #include "wx/msw/wince/time.h"
#endif
+#endif // ! __WXPALMOS5__
#ifdef __WXMAC__
-#include "wx/mac/private.h"
-#ifndef __DARWIN__
-#include "InternetConfig.h"
-#endif
+ #include "wx/osx/private.h"
#endif
+#ifndef __WXPALMOS5__
#if !defined(__MWERKS__) && !defined(__WXWINCE__)
#include <sys/types.h>
#include <sys/stat.h>
#endif
+#endif // ! __WXPALMOS5__
#if defined(__WXMSW__)
#include "wx/msw/private.h"
- #include "wx/msw/registry.h"
- #include <shellapi.h> // needed for SHELLEXECUTEINFO
+ #include "wx/filesys.h"
#endif
#if wxUSE_GUI && defined(__WXGTK__)
#if wxUSE_BASE
-// ----------------------------------------------------------------------------
-// common data
-// ----------------------------------------------------------------------------
-
// ============================================================================
// implementation
// ============================================================================
// Array used in DecToHex conversion routine.
-static wxChar hexArray[] = wxT("0123456789ABCDEF");
+static const wxChar hexArray[] = wxT("0123456789ABCDEF");
// Convert 2-digit hex number to decimal
int wxHexToDec(const wxString& buf)
if (buf.GetChar(0) >= wxT('A'))
firstDigit = buf.GetChar(0) - wxT('A') + 10;
else
- firstDigit = buf.GetChar(0) - wxT('0');
+ firstDigit = buf.GetChar(0) - wxT('0');
if (buf.GetChar(1) >= wxT('A'))
secondDigit = buf.GetChar(1) - wxT('A') + 10;
return wxEmptyString;
#endif
#else
- time_t now = time((time_t *) NULL);
+ time_t now = time(NULL);
char *date = ctime(&now);
date[24] = '\0';
return wxString::FromAscii(date);
#endif
}
+#if WXWIN_COMPATIBILITY_2_8
void wxUsleep(unsigned long milliseconds)
{
wxMilliSleep(milliseconds);
}
+#endif
const wxChar *wxGetInstallPrefix()
{
}
+// ----------------------------------------------------------------------------
+// wxPlatform
+// ----------------------------------------------------------------------------
+
/*
* Class to make it easier to specify platform-dependent values
*/
if ( !email )
return false;
- wxStrncpy(address, email, maxSize - 1);
- address[maxSize - 1] = wxT('\0');
+ wxStrlcpy(address, email.t_str(), maxSize);
return true;
}
{
if ( errno != ERANGE )
{
- wxLogSysError(_T("Failed to get current directory"));
+ wxLogSysError(wxT("Failed to get current directory"));
return wxEmptyString;
}
#if wxUSE_STREAMS
static bool ReadAll(wxInputStream *is, wxArrayString& output)
{
- wxCHECK_MSG( is, false, _T("NULL stream in wxExecute()?") );
+ wxCHECK_MSG( is, false, wxT("NULL stream in wxExecute()?") );
// the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
is->Reset();
}
// ----------------------------------------------------------------------------
-// wxApp::Yield() wrappers for backwards compatibility
+// Id functions
// ----------------------------------------------------------------------------
-bool wxYield()
-{
- return wxTheApp && wxTheApp->Yield();
-}
-
-bool wxYieldIfNeeded()
-{
- return wxTheApp && wxTheApp->Yield(true);
-}
-
// Id generation
static long wxCurrentId = 100;
/* Byte-wise swap two items of size SIZE. */
#define SWAP(a, b, size) \
- do \
- { \
- register size_t __size = (size); \
- register char *__a = (a), *__b = (b); \
+ do \
+ { \
+ register size_t __size = (size); \
+ register char *__a = (a), *__b = (b); \
do \
- { \
- char __tmp = *__a; \
+ { \
+ char __tmp = *__a; \
*__a++ = *__b; \
- *__b++ = __tmp; \
- } while (--__size > 0); \
+ *__b++ = __tmp; \
+ } while (--__size > 0); \
} while (0)
/* Discontinue quicksort algorithm when partition gets below this size.
}
}
+#endif // wxUSE_BASE
-#endif // wxUSE_BASE
// ============================================================================
// GUI-only functions from now on
#if wxUSE_GUI
+// this function is only really implemented for X11-based ports, including GTK1
+// (GTK2 sets detectable auto-repeat automatically anyhow)
+#if !(defined(__WXX11__) || defined(__WXMOTIF__) || \
+ (defined(__WXGTK__) && !defined(__WXGTK20__)))
+bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
+{
+ return true;
+}
+#endif // !X11-based port
+
// ----------------------------------------------------------------------------
// Launch default browser
// ----------------------------------------------------------------------------
-#ifdef __WXCOCOA__
-// Private method in Objective-C++ source file.
-bool wxCocoaLaunchDefaultBrowser(const wxString& url, int flags);
-#endif
-
-bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
-{
- wxUnusedVar(flags);
-
- // set the scheme of url to http if it does not have one
- // RR: This doesn't work if the url is just a local path
- wxString url(urlOrig);
- wxURI uri(url);
- if ( !uri.HasScheme() )
- {
- if (wxFileExists(urlOrig))
- url.Prepend( wxT("file://") );
- else
- url.Prepend(wxT("http://"));
- }
-
-
#if defined(__WXMSW__)
-#if wxUSE_IPC
- if ( flags & wxBROWSER_NEW_WINDOW )
- {
- // ShellExecuteEx() opens the URL in an existing window by default so
- // we can't use it if we need a new window
- wxRegKey key(wxRegKey::HKCR, uri.GetScheme() + _T("\\shell\\open"));
- if ( !key.Exists() )
- {
- // try default browser, it must be registered at least for http URLs
- key.SetName(wxRegKey::HKCR, _T("http\\shell\\open"));
- }
-
- if ( key.Exists() )
- {
- wxRegKey keyDDE(key, wxT("DDEExec"));
- if ( keyDDE.Exists() )
- {
- const wxString ddeTopic = wxRegKey(keyDDE, wxT("topic"));
-
- // we only know the syntax of WWW_OpenURL DDE request for IE,
- // optimistically assume that all other browsers are compatible
- // with it
- wxString ddeCmd;
- bool ok = ddeTopic == wxT("WWW_OpenURL");
- if ( ok )
- {
- ddeCmd = keyDDE.QueryDefaultValue();
- ok = !ddeCmd.empty();
- }
+// implemented in a port-specific utils source file:
+bool wxDoLaunchDefaultBrowser(const wxString& url, const wxString& scheme, int flags);
- if ( ok )
- {
- // for WWW_OpenURL, the index of the window to open the URL
- // in is -1 (meaning "current") by default, replace it with
- // 0 which means "new" (see KB article 160957)
- ok = ddeCmd.Replace(wxT("-1"), wxT("0"),
- false /* only first occurence */) == 1;
- }
-
- if ( ok )
- {
- // and also replace the parameters: the topic should
- // contain a placeholder for the URL
- ok = ddeCmd.Replace(wxT("%1"), url, false) == 1;
- }
-
- if ( ok )
- {
- // try to send it the DDE request now but ignore the errors
- wxLogNull noLog;
-
- const wxString ddeServer = wxRegKey(keyDDE, wxT("application"));
- if ( wxExecuteDDE(ddeServer, ddeTopic, ddeCmd) )
- return true;
-
- // this is not necessarily an error: maybe browser is
- // simply not running, but no matter, in any case we're
- // going to launch it using ShellExecuteEx() below now and
- // we shouldn't try to open a new window if we open a new
- // browser anyhow
- }
- }
- }
- }
-#endif // wxUSE_IPC
+#elif defined(__WXX11__) || defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || \
+ (defined(__WXOSX__) )
- WinStruct<SHELLEXECUTEINFO> sei;
- sei.lpFile = url.c_str();
- sei.lpVerb = _T("open");
- sei.nShow = SW_SHOWNORMAL;
+// implemented in a port-specific utils source file:
+bool wxDoLaunchDefaultBrowser(const wxString& url, int flags);
- ::ShellExecuteEx(&sei);
-
- const int nResult = (int) sei.hInstApp;
-
- // Firefox returns file not found for some reason, so make an exception
- // for it
- if ( nResult > 32 || nResult == SE_ERR_FNF )
- {
-#ifdef __WXDEBUG__
- // Log something if SE_ERR_FNF happens
- if ( nResult == SE_ERR_FNF )
- wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
-#endif // __WXDEBUG__
- return true;
- }
-#elif defined(__WXCOCOA__)
- // NOTE: We need to call the real implementation from src/cocoa/utils.mm
- // because the code must use Objective-C features.
- return wxCocoaLaunchDefaultBrowser(url, flags);
-#elif defined(__WXMAC__)
- OSStatus err;
- ICInstance inst;
- long int startSel;
- long int endSel;
-
- err = ICStart(&inst, 'STKA'); // put your app creator code here
- if (err == noErr)
- {
- if (err == noErr)
- {
- ConstStr255Param hint = 0;
- startSel = 0;
- endSel = url.length();
- err = ICLaunchURL(inst, hint, url.fn_str(), endSel, &startSel, &endSel);
- if (err != noErr)
- wxLogDebug(wxT("ICLaunchURL error %d"), (int) err);
- }
- ICStop(inst);
- return true;
- }
- else
- {
- wxLogDebug(wxT("ICStart error %d"), (int) err);
- return false;
- }
#else
- // (non-Mac, non-MSW)
-
-#ifdef __UNIX__
-
- wxString desktop = wxTheApp->GetTraits()->GetDesktopEnvironment();
-
- // GNOME and KDE desktops have some applications which should be always installed
- // together with their main parts, which give us the
- if (desktop == wxT("GNOME"))
- {
- wxArrayString errors;
- wxArrayString output;
- // gconf will tell us the path of the application to use as browser
- long res = wxExecute( wxT("gconftool-2 --get /desktop/gnome/applications/browser/exec"),
- output, errors, wxEXEC_NODISABLE );
- if (res >= 0 && errors.GetCount() == 0)
- {
- wxString cmd = output[0];
- cmd << _T(' ') << url;
- if (wxExecute(cmd))
- return true;
- }
- }
- else if (desktop == wxT("KDE"))
- {
- // kfmclient directly opens the given URL
- if (wxExecute(wxT("kfmclient openURL ") + url))
- return true;
- }
-#endif
+// a "generic" implementation:
+bool wxDoLaunchDefaultBrowser(const wxString& url, int flags)
+{
+ // on other platforms try to use mime types or wxExecute...
bool ok = false;
wxString cmd;
#if wxUSE_MIMETYPE
- wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(_T("html"));
+ wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(wxT("html"));
if ( ft )
{
wxString mt;
if ( !ok || cmd.empty() )
{
// fallback to checking for the BROWSER environment variable
- cmd = wxGetenv(wxT("BROWSER"));
- if ( !cmd.empty() )
- cmd << _T(' ') << url;
+ if ( !wxGetEnv(wxT("BROWSER"), &cmd) || cmd.empty() )
+ cmd << wxT(' ') << url;
}
ok = ( !cmd.empty() && wxExecute(cmd) );
// no file type for HTML extension
wxLogError(_("No default application configured for HTML files."));
-#endif // !wxUSE_MIMETYPE && !__WXMSW__
+ return false;
+}
+#endif
+
+static bool DoLaunchDefaultBrowserHelper(const wxString& urlOrig, int flags)
+{
+ // NOTE: we don't have to care about the wxBROWSER_NOBUSYCURSOR flag
+ // as it was already handled by wxLaunchDefaultBrowser
+
+ wxUnusedVar(flags);
+
+ wxString url(urlOrig), scheme;
+ wxURI uri(url);
+
+ // this check is useful to avoid that wxURI recognizes as scheme parts of
+ // the filename, in case urlOrig is a local filename
+ // (e.g. "C:\\test.txt" when parsed by wxURI reports a scheme == "C")
+ bool hasValidScheme = uri.HasScheme() && uri.GetScheme().length() > 1;
+
+#if defined(__WXMSW__)
+
+ // NOTE: when testing wxMSW's wxLaunchDefaultBrowser all possible forms
+ // of the URL/flags should be tested; e.g.:
+ //
+ // for (int i=0; i<2; i++)
+ // {
+ // // test arguments without a valid URL scheme:
+ // wxLaunchDefaultBrowser("C:\\test.txt", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // wxLaunchDefaultBrowser("wxwidgets.org", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ //
+ // // test arguments with different valid schemes:
+ // wxLaunchDefaultBrowser("file:/C%3A/test.txt", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // wxLaunchDefaultBrowser("http://wxwidgets.org", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // wxLaunchDefaultBrowser("mailto:user@host.org", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // }
+ // (assuming you have a C:\test.txt file)
+
+ if ( !hasValidScheme )
+ {
+ if (wxFileExists(urlOrig) || wxDirExists(urlOrig))
+ {
+ scheme = "file";
+ // do not prepend the file scheme to the URL as ShellExecuteEx() doesn't like it
+ }
+ else
+ {
+ url.Prepend(wxS("http://"));
+ scheme = "http";
+ }
+ }
+ else if ( hasValidScheme )
+ {
+ scheme = uri.GetScheme();
+
+ if ( uri.GetScheme() == "file" )
+ {
+ // TODO: extract URLToFileName() to some always compiled in
+ // function
+#if wxUSE_FILESYSTEM
+ // ShellExecuteEx() doesn't like the "file" scheme when opening local files;
+ // remove it
+ url = wxFileSystem::URLToFileName(url).GetFullPath();
+#endif // wxUSE_FILESYSTEM
+ }
+ }
+
+ if (wxDoLaunchDefaultBrowser(url, scheme, flags))
+ return true;
+ //else: call wxLogSysError
+#else
+ if ( !hasValidScheme )
+ {
+ // set the scheme of url to "http" or "file" if it does not have one
+ if (wxFileExists(urlOrig) || wxDirExists(urlOrig))
+ url.Prepend(wxS("file://"));
+ else
+ url.Prepend(wxS("http://"));
+ }
+
+ if (wxDoLaunchDefaultBrowser(url, flags))
+ return true;
+ //else: call wxLogSysError
+#endif
wxLogSysError(_("Failed to open URL \"%s\" in default browser."),
url.c_str());
return false;
}
+bool wxLaunchDefaultBrowser(const wxString& url, int flags)
+{
+ // NOTE: as documented, "url" may be both a real well-formed URL
+ // and a local file name
+
+ if ( flags & wxBROWSER_NOBUSYCURSOR )
+ return DoLaunchDefaultBrowserHelper(url, flags);
+
+ wxBusyCursor bc;
+ return DoLaunchDefaultBrowserHelper(url, flags);
+}
+
// ----------------------------------------------------------------------------
// Menu accelerators related functions
// ----------------------------------------------------------------------------
+#if WXWIN_COMPATIBILITY_2_6
wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out)
{
#if wxUSE_MENUS
return out;
}
+#endif
wxString wxStripMenuCodes(const wxString& in, int flags)
{
- wxASSERT_MSG( flags, _T("this is useless to call without any flags") );
+ wxASSERT_MSG( flags, wxT("this is useless to call without any flags") );
wxString out;
for ( size_t n = 0; n < len; n++ )
{
wxChar ch = in[n];
- if ( (flags & wxStrip_Mnemonics) && ch == _T('&') )
+ if ( (flags & wxStrip_Mnemonics) && ch == wxT('&') )
{
// 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
// can't be the last character of the string
if ( ++n == len )
{
- wxLogDebug(_T("Invalid menu string '%s'"), in.c_str());
+ wxLogDebug(wxT("Invalid menu string '%s'"), in.c_str());
}
else
{
ch = in[n];
}
}
- else if ( (flags & wxStrip_Accel) && ch == _T('\t') )
+ else if ( (flags & wxStrip_Accel) && ch == wxT('\t') )
{
// everything after TAB is accel string, exit the loop
break;
int wxMessageBox(const wxString& message, const wxString& caption, long style,
wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y) )
{
- long decorated_style = style;
-
- if ( ( style & ( wxICON_EXCLAMATION | wxICON_HAND | wxICON_INFORMATION | wxICON_QUESTION ) ) == 0 )
+ // add the appropriate icon unless this was explicitly disabled by use of
+ // wxICON_NONE
+ if ( !(style & wxICON_NONE) && !(style & wxICON_MASK) )
{
- decorated_style |= ( style & wxYES ) ? wxICON_QUESTION : wxICON_INFORMATION ;
+ style |= style & wxYES ? wxICON_QUESTION : wxICON_INFORMATION;
}
- wxMessageDialog dialog(parent, message, caption, decorated_style);
+ wxMessageDialog dialog(parent, message, caption, style);
int ans = dialog.ShowModal();
switch ( ans )
return wxCANCEL;
}
- wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
+ wxFAIL_MSG( wxT("unexpected return code from wxMessageDialog") );
return wxCANCEL;
}
{
// don't translate these strings, they're for diagnostics purposes only
wxString msg;
- msg.Printf(_T("wxWidgets Library (%s port)\n")
- _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
- _T("Runtime version of toolkit used is %d.%d.%s\n")
- _T("Copyright (c) 1995-2007 wxWidgets team"),
- wxPlatformInfo::Get().GetPortIdName().c_str(),
+ msg.Printf(wxS("wxWidgets Library (%s port)\n")
+ wxS("Version %d.%d.%d (Unicode: %s, debug level: %d),\n")
+ wxS("compiled at %s %s\n\n")
+ wxS("Runtime version of toolkit used is %d.%d.\n"),
+ wxPlatformInfo::Get().GetPortIdName(),
wxMAJOR_VERSION,
wxMINOR_VERSION,
wxRELEASE_NUMBER,
-#if wxUSE_UNICODE
- L" (Unicode)",
-#else
- wxEmptyString,
-#endif
-#ifdef __WXDEBUG__
- _T(" Debug build"),
+#if wxUSE_UNICODE_UTF8
+ "UTF-8",
+#elif wxUSE_UNICODE
+ "wchar_t",
#else
- wxEmptyString,
+ "none",
#endif
+ wxDEBUG_LEVEL,
__TDATE__,
__TTIME__,
wxPlatformInfo::Get().GetToolkitMajorVersion(),
- wxPlatformInfo::Get().GetToolkitMinorVersion(),
+ wxPlatformInfo::Get().GetToolkitMinorVersion()
+ );
+
#ifdef __WXGTK__
- wxString::Format("\nThe compile-time GTK+ version is %d.%d.%d.",
- GTK_MAJOR_VERSION,
- GTK_MINOR_VERSION,
- GTK_MICRO_VERSION).c_str()
-#else
- wxEmptyString
-#endif
- );
- wxMessageBox(msg, _T("wxWidgets information"),
+ msg += wxString::Format("Compile-time GTK+ version is %d.%d.%d.\n",
+ GTK_MAJOR_VERSION,
+ GTK_MINOR_VERSION,
+ GTK_MICRO_VERSION);
+#endif // __WXGTK__
+
+ msg += wxS("\nCopyright (c) 1995-2010 wxWidgets team");
+
+ wxMessageBox(msg, wxT("wxWidgets information"),
wxICON_INFORMATION | wxOK,
parent);
}
#if wxUSE_COLOURDLG
-wxColour wxGetColourFromUser(wxWindow *parent,
- const wxColour& colInit,
+wxColour wxGetColourFromUser(wxWindow *parent,
+ const wxColour& colInit,
const wxString& caption,
wxColourData *ptrData)
{
node->GetData()->Enable(enable);
}
+wxWindowDisabler::wxWindowDisabler(bool disable)
+{
+ m_disabled = disable;
+ if ( disable )
+ DoDisable();
+}
+
wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip)
+{
+ m_disabled = true;
+ DoDisable(winToSkip);
+}
+
+void wxWindowDisabler::DoDisable(wxWindow *winToSkip)
{
// remember the top level windows which were already disabled, so that we
// don't reenable them later
wxWindowDisabler::~wxWindowDisabler()
{
+ if ( !m_disabled )
+ return;
+
wxWindowList::compatibility_iterator node;
for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
{
return rc;
}
-// Don't synthesize KeyUp events holding down a key and producing KeyDown
-// events with autorepeat. On by default and always on in wxMSW. wxGTK version
-// in utilsgtk.cpp.
-#ifndef __WXGTK__
-bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
+// ----------------------------------------------------------------------------
+// wxApp::Yield() wrappers for backwards compatibility
+// ----------------------------------------------------------------------------
+
+bool wxYield()
{
- return true; // detectable auto-repeat is the only mode MSW supports
+ return wxTheApp && wxTheApp->Yield();
+}
+
+bool wxYieldIfNeeded()
+{
+ return wxTheApp && wxTheApp->Yield(true);
}
-#endif // !wxGTK
#endif // wxUSE_GUI