#endif // wxUSE_GUI
#endif // WX_PRECOMP
+#include "wx/process.h"
+#include "wx/txtstrm.h"
+
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
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
#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
}
#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;
+}