]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/utilscmn.cpp
Improved handling of selection/deselection events.
[wxWidgets.git] / src / common / utilscmn.cpp
index a9fda2f4acc5416af274f405994ddf577124342b..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>
     #endif
 #endif
 
+#if wxUSE_GUI
+    #include "wx/colordlg.h"
+#endif // wxUSE_GUI
+
 #include <time.h>
 
 #ifndef __MWERKS__
@@ -865,19 +872,14 @@ int wxMessageBox(const wxString& message, const wxString& caption, long style,
     {
         case wxID_OK:
             return wxOK;
-            break;
         case wxID_YES:
             return wxYES;
-            break;
         case wxID_NO:
             return wxNO;
-            break;
         default:
         case wxID_CANCEL:
             return wxCANCEL;
-            break;
     }
-    return ans;
 }
 
 #if wxUSE_TEXTDLG
@@ -885,14 +887,58 @@ wxString wxGetTextFromUser(const wxString& message, const wxString& caption,
                         const wxString& defaultValue, wxWindow *parent,
                         int x, int y, bool WXUNUSED(centre) )
 {
+    wxString str;
     wxTextEntryDialog dialog(parent, message, caption, defaultValue, wxOK|wxCANCEL, wxPoint(x, y));
     if (dialog.ShowModal() == wxID_OK)
-        return dialog.GetValue();
-    else
-        return wxString("");
+    {
+        str = dialog.GetValue();
+    }
+
+    return str;
 }
+
+wxString wxGetPasswordFromUser(const wxString& message,
+                               const wxString& caption,
+                               const wxString& defaultValue,
+                               wxWindow *parent)
+{
+    wxString str;
+    wxTextEntryDialog dialog(parent, message, caption, defaultValue,
+                             wxOK | wxCANCEL | wxTE_PASSWORD);
+    if ( dialog.ShowModal() == wxID_OK )
+    {
+        str = dialog.GetValue();
+    }
+
+    return str;
+}
+
 #endif // wxUSE_TEXTDLG
 
+wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit)
+{
+      wxColourData data;
+      data.SetChooseFull(TRUE);
+      if ( colInit.Ok() )
+      {
+          data.SetColour((wxColour &)colInit); // const_cast
+      }
+
+      wxColour colRet;
+      wxColourDialog dialog(parent, &data);
+      if ( dialog.ShowModal() == wxID_OK )
+      {
+          colRet = dialog.GetColourData().GetColour();
+      }
+      //else: leave it invalid
+
+      return colRet;
+}
+
+// ----------------------------------------------------------------------------
+// missing C RTL functions (FIXME shouldn't be here at all)
+// ----------------------------------------------------------------------------
+
 #ifdef __MWERKS__
 char *strdup(const char *s)
 {
@@ -911,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();
+        }
+    }
 }
 
-// Yield to other apps/messages and disable user input
+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();
+    }
+}
+
+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
@@ -934,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
 
@@ -1074,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;
+}