X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d545f8030a9ba07dcd5cd146dae2898ced7a48c1..af58844636f51ca9c9350c66de3baf427d3e8646:/src/common/utilscmn.cpp diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 8a0dfa3b2f..2a8dbf931b 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -54,7 +54,7 @@ #include "wx/config.h" #if defined(__WXWINCE__) && wxUSE_DATETIME -#include "wx/datetime.h" + #include "wx/datetime.h" #endif #include @@ -75,35 +75,35 @@ #include "wx/statusbr.h" #endif // wxUSE_GUI +#ifndef __WXPALMOS5__ #ifndef __WXWINCE__ -#include + #include #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 #include #endif +#endif // ! __WXPALMOS5__ #if defined(__WXMSW__) #include "wx/msw/private.h" - #include "wx/msw/registry.h" - #include // needed for SHELLEXECUTEINFO + #include "wx/filesys.h" #endif -#if wxUSE_BASE +#if wxUSE_GUI && defined(__WXGTK__) + #include // for GTK_XXX_VERSION constants +#endif -// ---------------------------------------------------------------------------- -// common data -// ---------------------------------------------------------------------------- +#if wxUSE_BASE // ============================================================================ // implementation @@ -120,7 +120,7 @@ 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; @@ -140,6 +140,15 @@ void wxDecToHex(int dec, wxChar *buf) buf[2] = 0; } +// Convert decimal integer to 2 characters +void wxDecToHex(int dec, char* ch1, char* ch2) +{ + int firstDigit = (int)(dec/16.0); + int secondDigit = (int)(dec - (firstDigit*16.0)); + (*ch1) = (char) hexArray[firstDigit]; + (*ch2) = (char) hexArray[secondDigit]; +} + // Convert decimal integer to 2-character hex string wxString wxDecToHex(int dec) { @@ -152,6 +161,16 @@ wxString wxDecToHex(int dec) // misc functions // ---------------------------------------------------------------------------- +// 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) ) +{ + return true; // detectable auto-repeat is the only mode MSW supports +} +#endif // !wxGTK + // Return the current date/time wxString wxNow() { @@ -163,17 +182,19 @@ wxString wxNow() 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() { @@ -210,6 +231,10 @@ bool wxIsPlatformLittleEndian() } +// ---------------------------------------------------------------------------- +// wxPlatform +// ---------------------------------------------------------------------------- + /* * Class to make it easier to specify platform-dependent values */ @@ -422,8 +447,7 @@ bool wxGetEmailAddress(wxChar *address, int maxSize) if ( !email ) return false; - wxStrncpy(address, email, maxSize - 1); - address[maxSize - 1] = wxT('\0'); + wxStrlcpy(address, email.t_str(), maxSize); return true; } @@ -631,19 +655,9 @@ long wxExecute(const wxString& command, } // ---------------------------------------------------------------------------- -// 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; @@ -666,193 +680,280 @@ wxRegisterId (long id) wxCurrentId = id + 1; } -#endif // wxUSE_BASE +// ---------------------------------------------------------------------------- +// wxQsort, adapted by RR to allow user_data +// ---------------------------------------------------------------------------- -// ============================================================================ -// GUI-only functions from now on -// ============================================================================ +/* This file is part of the GNU C Library. + Written by Douglas C. Schmidt (schmidt@ics.uci.edu). -#if wxUSE_GUI + Douglas Schmidt kindly gave permission to relicence the + code under the wxWindows licence: -// ---------------------------------------------------------------------------- -// Launch default browser -// ---------------------------------------------------------------------------- +From: "Douglas C. Schmidt" +To: Robert Roebling +Subject: Re: qsort licence +Date: Mon, 23 Jul 2007 03:44:25 -0500 +Sender: schmidt@dre.vanderbilt.edu +Message-Id: <20070723084426.64F511000A8@tango.dre.vanderbilt.edu> -#ifdef __WXCOCOA__ -// Private method in Objective-C++ source file. -bool wxCocoaLaunchDefaultBrowser(const wxString& url, int flags); -#endif +Hi Robert, -bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags) -{ - wxUnusedVar(flags); +> [...] I'm asking if you'd be willing to relicence your code +> under the wxWindows licence. [...] - // 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://")); - } +That's fine with me [...] +Thanks, + + Doug */ -#if defined(__WXMSW__) -#if wxUSE_IPC - if ( flags & wxBROWSER_NEW_WINDOW ) +/* 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 \ + { \ + char __tmp = *__a; \ + *__a++ = *__b; \ + *__b++ = __tmp; \ + } while (--__size > 0); \ + } while (0) + +/* Discontinue quicksort algorithm when partition gets below this size. + This particular magic number was chosen to work best on a Sun 4/260. */ +#define MAX_THRESH 4 + +/* Stack node declarations used to store unfulfilled partition obligations. */ +typedef struct + { + char *lo; + char *hi; + } stack_node; + +/* The next 4 #defines implement a very fast in-line stack abstraction. */ +#define STACK_SIZE (8 * sizeof(unsigned long int)) +#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) +#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) +#define STACK_NOT_EMPTY (stack < top) + + +/* Order size using quicksort. This implementation incorporates + four optimizations discussed in Sedgewick: + + 1. Non-recursive, using an explicit stack of pointer that store the + next array partition to sort. To save time, this maximum amount + of space required to store an array of MAX_INT is allocated on the + stack. Assuming a 32-bit integer, this needs only 32 * + sizeof(stack_node) == 136 bits. Pretty cheap, actually. + + 2. Chose the pivot element using a median-of-three decision tree. + This reduces the probability of selecting a bad pivot value and + eliminates certain extraneous comparisons. + + 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving + insertion sort to order the MAX_THRESH items within each partition. + This is a big win, since insertion sort is faster for small, mostly + sorted array segments. + + 4. The larger of the two sub-partitions is always pushed onto the + stack first, with the algorithm then concentrating on the + smaller partition. This *guarantees* no more than log (n) + stack size is needed (actually O(1) in this case)! */ + +void wxQsort(void *const pbase, size_t total_elems, + size_t size, CMPFUNCDATA cmp, const void* user_data) +{ + register char *base_ptr = (char *) pbase; + const size_t max_thresh = MAX_THRESH * size; + + if (total_elems == 0) + /* Avoid lossage with unsigned arithmetic below. */ + return; + + if (total_elems > MAX_THRESH) { - // 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")); - } + char *lo = base_ptr; + char *hi = &lo[size * (total_elems - 1)]; + stack_node stack[STACK_SIZE]; + stack_node *top = stack; + + PUSH (NULL, NULL); - if ( key.Exists() ) + while (STACK_NOT_EMPTY) { - wxRegKey keyDDE(key, wxT("DDEExec")); - if ( keyDDE.Exists() ) + char *left_ptr; + char *right_ptr; + + /* Select median value from among LO, MID, and HI. Rearrange + LO and HI so the three values are sorted. This lowers the + probability of picking a pathological pivot value and + skips a comparison for both the LEFT_PTR and RIGHT_PTR. */ + + char *mid = lo + size * ((hi - lo) / size >> 1); + + if ((*cmp) ((void *) mid, (void *) lo, user_data) < 0) + SWAP (mid, lo, size); + if ((*cmp) ((void *) hi, (void *) mid, user_data) < 0) + SWAP (mid, hi, size); + else + goto jump_over; + if ((*cmp) ((void *) mid, (void *) lo, user_data) < 0) + SWAP (mid, lo, size); + jump_over:; + left_ptr = lo + size; + right_ptr = hi - size; + + /* Here's the famous ``collapse the walls'' section of quicksort. + Gotta like those tight inner loops! They are the main reason + that this algorithm runs much faster than others. */ + do { - 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(); - } + while ((*cmp) ((void *) left_ptr, (void *) mid, user_data) < 0) + left_ptr += size; - 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; - } + while ((*cmp) ((void *) mid, (void *) right_ptr, user_data) < 0) + right_ptr -= size; - if ( ok ) + if (left_ptr < right_ptr) { - // and also replace the parameters: the topic should - // contain a placeholder for the URL - ok = ddeCmd.Replace(wxT("%1"), url, false) == 1; + SWAP (left_ptr, right_ptr, size); + if (mid == left_ptr) + mid = right_ptr; + else if (mid == right_ptr) + mid = left_ptr; + left_ptr += size; + right_ptr -= size; } - - if ( ok ) + else if (left_ptr == right_ptr) { - // 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 + left_ptr += size; + right_ptr -= size; + break; } } + while (left_ptr <= right_ptr); + + /* Set up pointers for next iteration. First determine whether + left and right partitions are below the threshold size. If so, + ignore one or both. Otherwise, push the larger partition's + bounds on the stack and continue sorting the smaller one. */ + + if ((size_t) (right_ptr - lo) <= max_thresh) + { + if ((size_t) (hi - left_ptr) <= max_thresh) + /* Ignore both small partitions. */ + POP (lo, hi); + else + /* Ignore small left partition. */ + lo = left_ptr; + } + else if ((size_t) (hi - left_ptr) <= max_thresh) + /* Ignore small right partition. */ + hi = right_ptr; + else if ((right_ptr - lo) > (hi - left_ptr)) + { + /* Push larger left partition indices. */ + PUSH (lo, right_ptr); + lo = left_ptr; + } + else + { + /* Push larger right partition indices. */ + PUSH (left_ptr, hi); + hi = right_ptr; + } } } -#endif // wxUSE_IPC - WinStruct sei; - sei.lpFile = url.c_str(); - sei.lpVerb = _T("open"); - sei.nShow = SW_SHOWNORMAL; + /* Once the BASE_PTR array is partially sorted by quicksort the rest + is completely sorted using insertion sort, since this is efficient + for partitions below MAX_THRESH size. BASE_PTR points to the beginning + of the array to sort, and END_PTR points at the very last element in + the array (*not* one beyond it!). */ - ::ShellExecuteEx(&sei); + { + char *const end_ptr = &base_ptr[size * (total_elems - 1)]; + char *tmp_ptr = base_ptr; + char *thresh = base_ptr + max_thresh; + if ( thresh > end_ptr ) + thresh = end_ptr; + register char *run_ptr; - const int nResult = (int) sei.hInstApp; + /* Find smallest element in first threshold and place it at the + array's beginning. This is the smallest array element, + and the operation speeds up insertion sort's inner loop. */ - // 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 !TARGET_CARBON - err = ICFindConfigFile(inst, 0, NULL); -#endif - 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) + for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size) + if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, user_data) < 0) + tmp_ptr = run_ptr; -#ifdef __UNIX__ + if (tmp_ptr != base_ptr) + SWAP (tmp_ptr, base_ptr, size); - wxString desktop = wxTheApp->GetTraits()->GetDesktopEnvironment(); + /* Insertion sort, running from left-hand-side up to right-hand-side. */ - // 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; + run_ptr = base_ptr + size; + while ((run_ptr += size) <= end_ptr) + { + tmp_ptr = run_ptr - size; + while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, user_data) < 0) + tmp_ptr -= size; + + tmp_ptr += size; + if (tmp_ptr != run_ptr) + { + char *trav; + + trav = run_ptr + size; + while (--trav >= run_ptr) + { + char c = *trav; + char *hi, *lo; + + for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo) + *hi = *lo; + *hi = c; + } + } + } + } +} - // 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 +#endif // wxUSE_BASE + + + +// ============================================================================ +// GUI-only functions from now on +// ============================================================================ + +#if wxUSE_GUI + +// ---------------------------------------------------------------------------- +// Launch default browser +// ---------------------------------------------------------------------------- + +#if defined(__WXMSW__) + +// implemented in a port-specific utils source file: +bool wxDoLaunchDefaultBrowser(const wxString& url, const wxString& scheme, int flags); + +#elif defined(__WXX11__) || defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || \ + (defined(__WXMAC__) && !defined(__WXOSX_IPHONE__)) + +// implemented in a port-specific utils source file: +bool wxDoLaunchDefaultBrowser(const wxString& url, int flags); + +#else + +// 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; @@ -872,8 +973,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags) if ( !ok || cmd.empty() ) { // fallback to checking for the BROWSER environment variable - cmd = wxGetenv(wxT("BROWSER")); - if ( !cmd.empty() ) + if ( !wxGetEnv(wxT("BROWSER"), &cmd) || cmd.empty() ) cmd << _T(' ') << url; } @@ -882,24 +982,119 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags) return ok; // no file type for HTML extension - wxLogError(_T("No default application configured for HTML files.")); + wxLogError(_("No default application configured for HTML files.")); + + 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 -#endif // !wxUSE_MIMETYPE && !__WXMSW__ + 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(_T("Failed to open URL \"%s\" in default browser."), + 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 - wxString s = wxMenuItem::GetLabelFromText(in); + wxString s = wxMenuItem::GetLabelText(in); #else wxString str(in); wxString s = wxStripMenuCodes(str); @@ -917,6 +1112,7 @@ wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out) return out; } +#endif wxString wxStripMenuCodes(const wxString& in, int flags) { @@ -988,13 +1184,19 @@ wxFindWindowByName (const wxString& name, wxWindow * parent) // Returns menu item id or wxNOT_FOUND if none. int -wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& itemString) +wxFindMenuItemId(wxFrame *frame, + const wxString& menuString, + const wxString& itemString) { #if wxUSE_MENUS wxMenuBar *menuBar = frame->GetMenuBar (); if ( menuBar ) return menuBar->FindMenuItem (menuString, itemString); -#endif // wxUSE_MENUS +#else // !wxUSE_MENUS + wxUnusedVar(frame); + wxUnusedVar(menuString); + wxUnusedVar(itemString); +#endif // wxUSE_MENUS/!wxUSE_MENUS return wxNOT_FOUND; } @@ -1081,14 +1283,14 @@ wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt) 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 ) @@ -1108,6 +1310,46 @@ int wxMessageBox(const wxString& message, const wxString& caption, long style, return wxCANCEL; } +void wxInfoMessageBox(wxWindow* parent) +{ + // 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-2009 wxWidgets team"), + wxPlatformInfo::Get().GetPortIdName().c_str(), + wxMAJOR_VERSION, + wxMINOR_VERSION, + wxRELEASE_NUMBER, +#if wxUSE_UNICODE + L" (Unicode)", +#else + wxEmptyString, +#endif +#ifdef __WXDEBUG__ + _T(" Debug build"), +#else + wxEmptyString, +#endif + __TDATE__, + __TTIME__, + wxPlatformInfo::Get().GetToolkitMajorVersion(), + 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"), + wxICON_INFORMATION | wxOK, + parent); +} + #endif // wxUSE_MSGDLG #if wxUSE_TEXTDLG @@ -1162,24 +1404,56 @@ wxString wxGetPasswordFromUser(const wxString& message, #if wxUSE_COLOURDLG -wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit, const wxString& caption) +wxColour wxGetColourFromUser(wxWindow *parent, + const wxColour& colInit, + const wxString& caption, + wxColourData *ptrData) { + // contains serialized representation of wxColourData used the last time + // the dialog was shown: we want to reuse it the next time in order to show + // the same custom colours to the user (and we can't just have static + // wxColourData itself because it's a GUI object and so should be destroyed + // before GUI shutdown and doing it during static cleanup is too late) + static wxString s_strColourData; + wxColourData data; - data.SetChooseFull(true); - if ( colInit.Ok() ) + if ( !ptrData ) { - data.SetColour((wxColour &)colInit); // const_cast + ptrData = &data; + if ( !s_strColourData.empty() ) + { + if ( !data.FromString(s_strColourData) ) + { + wxFAIL_MSG( "bug in wxColourData::FromString()?" ); + } + +#ifdef __WXMSW__ + // we don't get back the "choose full" flag value from the native + // dialog and so we can't preserve it between runs, so we decide to + // always use it as it seems better than not using it (user can + // just ignore the extra controls in the dialog but having to click + // a button each time to show them would be very annoying + data.SetChooseFull(true); +#endif // __WXMSW__ + } + } + + if ( colInit.IsOk() ) + { + ptrData->SetColour(colInit); } wxColour colRet; - wxColourDialog dialog(parent, &data); + wxColourDialog dialog(parent, ptrData); if (!caption.empty()) dialog.SetTitle(caption); if ( dialog.ShowModal() == wxID_OK ) { - colRet = dialog.GetColourData().GetColour(); + *ptrData = dialog.GetColourData(); + colRet = ptrData->GetColour(); + s_strColourData = ptrData->ToString(); } - //else: leave it invalid + //else: leave colRet invalid return colRet; } @@ -1222,7 +1496,20 @@ void wxEnableTopLevelWindows(bool enable) 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 @@ -1254,6 +1541,9 @@ wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip) wxWindowDisabler::~wxWindowDisabler() { + if ( !m_disabled ) + return; + wxWindowList::compatibility_iterator node; for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() ) { @@ -1283,14 +1573,18 @@ bool wxSafeYield(wxWindow *win, bool onlyIfNeeded) 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