]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/utilscmn.cpp
Improved handling of selection/deselection events.
[wxWidgets.git] / src / common / utilscmn.cpp
index 5a685ccc754f50eb7f42318c072f493ea31c96ed..3f62793a9eb1930cd8b1b42371f8619e1ff288ed 100644 (file)
@@ -48,6 +48,9 @@
     #endif // wxUSE_GUI
 #endif // WX_PRECOMP
 
+#include "wx/process.h"
+#include "wx/txtstrm.h"
+
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -954,21 +957,73 @@ int isascii( int c )
 
 void wxEnableTopLevelWindows(bool enable)
 {
-   wxWindowList::Node *node;
-   for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
-      node->GetData()->Enable(enable);
+    wxWindowList::Node *node;
+    for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
+        node->GetData()->Enable(enable);
+}
+
+static void wxFindDisabledWindows(wxWindowList& winDisabled, wxWindow *win)
+{
+    wxWindowList::Node *node;
+    for ( node = win->GetChildren().GetFirst(); node; node = node->GetNext() )
+    {
+        wxWindow *child = node->GetData();
+        wxFindDisabledWindows(winDisabled, child);
+
+        if ( child->IsEnabled() )
+        {
+            winDisabled.Append(child);
+            child->Disable();
+        }
+    }
+}
+
+wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip)
+{
+    // remember all windows we're going to (temporarily) disable
+    m_winDisabled = new wxWindowList;
+
+    wxWindowList::Node *node;
+    for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
+    {
+        wxWindow *winTop = node->GetData();
+        if ( winTop->IsEnabled() )
+        {
+            wxFindDisabledWindows(*m_winDisabled, winTop);
+
+            m_winDisabled->Append(winTop);
+            winTop->Disable();
+        }
+    }
+
+    if ( winToSkip && m_winDisabled->Find(winToSkip) )
+    {
+        // always enable ourselves
+        m_winDisabled->DeleteObject(winToSkip);
+        winToSkip->Enable();
+    }
 }
 
-// Yield to other apps/messages and disable user input
+wxWindowDisabler::~wxWindowDisabler()
+{
+    wxWindowList::Node *node;
+    for ( node = m_winDisabled->GetFirst(); node; node = node->GetNext() )
+    {
+        node->GetData()->Enable();
+    }
+
+    delete m_winDisabled;
+}
+
+// Yield to other apps/messages and disable user input to all windows except
+// the given one
 bool wxSafeYield(wxWindow *win)
 {
-   wxEnableTopLevelWindows(FALSE);
-   // always enable ourselves
-   if ( win )
-      win->Enable(TRUE);
-   bool rc = wxYield();
-   wxEnableTopLevelWindows(TRUE);
-   return rc;
+    wxWindowDisabler wd;
+
+    bool rc = wxYield();
+
+    return rc;
 }
 
 // Don't synthesize KeyUp events holding down a key and producing KeyDown
@@ -977,7 +1032,7 @@ bool wxSafeYield(wxWindow *win)
 #ifndef __WXGTK__
 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
 {
-   return TRUE;          // detectable auto-repeat is the only mode MSW supports
+    return TRUE;    // detectable auto-repeat is the only mode MSW supports
 }
 #endif // !wxGTK
 
@@ -1117,3 +1172,31 @@ wxString wxGetCurrentDir()
 }
 
 #endif // 0
+
+// ----------------------------------------------------------------------------
+// wxExecute
+// ----------------------------------------------------------------------------
+
+long wxExecute(const wxString& command, wxArrayString& output)
+{
+    // create a wxProcess which will capture the output
+    wxProcess *process = new wxProcess;
+    process->Redirect();
+
+    long rc = wxExecute(command, TRUE /* sync */, process);
+    if ( rc != -1 )
+    {
+        wxInputStream& is = *process->GetInputStream();
+        wxTextInputStream tis(is);
+        while ( !is.Eof() )
+        {
+            wxString line = tis.ReadLine();
+            if ( is.LastError() )
+                break;
+
+            output.Add(line);
+        }
+    }
+
+    return rc;
+}