]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/utilscmn.cpp
BIG glitch.
[wxWidgets.git] / src / common / utilscmn.cpp
index be9df90d2fb7162e8d935856b423a59d4b10c564..52b8878187060f46b40e249b37de2a950de351bb 100644 (file)
 
 extern char *wxBuffer;
 
+// ----------------------------------------------------------------------------
+// private functions
+// ----------------------------------------------------------------------------
+
+static wxWindow *wxFindWindowByLabel1(const wxString& title, wxWindow * parent);
+static wxWindow *wxFindWindowByName1 (const wxString& title, wxWindow * parent);
+
 #ifdef __WXMAC__
 int strcasecmp(const char *str_1, const char *str_2)
 {
@@ -359,28 +366,6 @@ wxString wxNow( void )
   return wxString(date);
 }
 
-/* Get Full RFC822 style email address */
-bool
-wxGetEmailAddress (char *address, int maxSize)
-{
-  char host[65];
-  char user[65];
-
-  if (wxGetHostName(host, 64) == FALSE)
-    return FALSE;
-  if (wxGetUserId(user, 64) == FALSE)
-    return FALSE;
-
-  char tmp[130];
-  strcpy(tmp, user);
-  strcat(tmp, "@");
-  strcat(tmp, host);
-
-  strncpy(address, tmp, maxSize - 1);
-  address[maxSize-1] = '\0';
-  return TRUE;
-}
-
 /*
  * Strip out any menu codes
  */
@@ -440,53 +425,54 @@ wxString wxStripMenuCodes(const wxString& str)
  *
  */
 
-static wxWindow *wxFindWindowByLabel1 (const wxString& title, wxWindow * parent);
-
 wxWindow *
 wxFindWindowByLabel (const wxString& title, wxWindow * parent)
 {
-  if (parent)
+    if (parent)
     {
-      return wxFindWindowByLabel1 (title, parent);
+        return wxFindWindowByLabel1(title, parent);
     }
-  else
+    else
     {
-      for (wxNode * node = wxTopLevelWindows.First (); node; node = node->Next ())
+        for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
+              node;
+              node = node->GetNext() )
         {
-          wxWindow *win = (wxWindow *) node->Data ();
-          wxWindow *retwin = wxFindWindowByLabel1 (title, win);
-          if (retwin)
-            return retwin;
+            wxWindow *win = node->GetData();
+            wxWindow *retwin = wxFindWindowByLabel1 (title, win);
+            if (retwin)
+                return retwin;
         }                        // for()
 
     }
-  return (wxWindow *) NULL;
+    return (wxWindow *) NULL;
 }
 
 // Recursive
 static wxWindow *
 wxFindWindowByLabel1 (const wxString& title, wxWindow * parent)
 {
-  if (parent)
+    if (parent)
     {
-      if (parent->GetLabel() == title)
-                return parent;
+        if (parent->GetLabel() == title)
+            return parent;
     }
 
-  if (parent)
+    if (parent)
     {
-      for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ())
+        for ( wxNode * node = parent->GetChildren().GetFirst();
+              node;
+              node = node->GetNext() )
         {
-          wxWindow *win = (wxWindow *) node->Data ();
-          wxWindow *retwin = wxFindWindowByLabel1 (title, win);
-          if (retwin)
-            return retwin;
-        }                        // for()
+            wxWindow *win = (wxWindow *)node->GetData();
+            wxWindow *retwin = wxFindWindowByLabel1 (title, win);
+            if (retwin)
+                return retwin;
+        }
 
     }
 
-  return (wxWindow *) NULL;                        // Not found
-
+    return (wxWindow *) NULL;                        // Not found
 }
 
 /*
@@ -495,28 +481,29 @@ wxFindWindowByLabel1 (const wxString& title, wxWindow * parent)
  *
  */
 
-static wxWindow *wxFindWindowByName1 (const wxString& title, wxWindow * parent);
-
 wxWindow *
 wxFindWindowByName (const wxString& title, wxWindow * parent)
 {
-  if (parent)
+    if (parent)
     {
-      return wxFindWindowByName1 (title, parent);
+        return wxFindWindowByName1 (title, parent);
     }
-  else
+    else
     {
-      for (wxNode * node = wxTopLevelWindows.First (); node; node = node->Next ())
+        for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
+              node;
+              node = node->GetNext() )
         {
-          wxWindow *win = (wxWindow *) node->Data ();
-          wxWindow *retwin = wxFindWindowByName1 (title, win);
-          if (retwin)
-            return retwin;
-        }                        // for()
+            wxWindow *win = node->GetData();
+            wxWindow *retwin = wxFindWindowByName1 (title, win);
+            if (retwin)
+                return retwin;
+        }
 
     }
-  // Failed? Try by label instead.
-  return wxFindWindowByLabel(title, parent);
+
+    // Failed? Try by label instead.
+    return wxFindWindowByLabel(title, parent);
 }
 
 // Recursive
@@ -752,21 +739,23 @@ whereami(name)
 // Yield to other apps/messages and disable user input
 bool wxSafeYield(wxWindow *win)
 {
-   wxNode *node;
-   for ( node = wxTopLevelWindows.GetFirst();
-         node;
-         node = node->GetNext() )
-      ((wxWindow*)node->GetData())->Enable(FALSE);
-   
-   // always enable ourselves
-   if(win) win->Enable(true);
-   bool rc = wxYield();
+    wxWindowList::Node *node;
+    for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
+    {
+        node->GetData()->Enable(FALSE);
+    }
+
+    // always enable ourselves
+    if ( win )
+        win->Enable(TRUE);
+    bool rc = wxYield();
 
-   for ( node = wxTopLevelWindows.GetFirst();
-         node;
-         node = node->GetNext() )
-      ((wxWindow*)node->GetData())->Enable(TRUE);
-   return rc;
+    for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
+    {
+        node->GetData()->Enable(TRUE);
+    }
+
+    return rc;
 }
 
 /*
@@ -822,37 +811,81 @@ int isascii( int c )
 }
 #endif
 
-bool wxGetUserId(wxString& buf)
+// ----------------------------------------------------------------------------
+// network and user id functions
+// ----------------------------------------------------------------------------
+
+// Get Full RFC822 style email address
+bool wxGetEmailAddress(char *address, int maxSize)
 {
-    bool success = wxGetUserId(wxBuffer, 500);
-    if (success)
-    {
-        buf = wxBuffer;
-        return TRUE;
-    }
-    else
+    wxString email = wxGetEmailAddress();
+    if ( !email )
         return FALSE;
+
+    strncpy(address, email, maxSize - 1);
+    address[maxSize - 1] = '\0';
+
+    return TRUE;
 }
 
-bool wxGetUserName(wxString& buf)
+wxString wxGetEmailAddress()
 {
-    bool success = wxGetUserName(wxBuffer, 500);
-    if (success)
+    wxString email;
+
+    wxString host = wxGetHostName();
+    if ( !!host )
     {
-        buf = wxBuffer;
-        return TRUE;
+        wxString user = wxGetUserId();
+        if ( !!user )
+        {
+            wxString email(user);
+            email << '@' << host;
+        }
     }
-    else
-        return FALSE;
+
+    return email;
+}
+
+wxString wxGetUserId()
+{
+    static const int maxLoginLen = 256; // FIXME arbitrary number
+
+    wxString buf;
+    bool ok = wxGetUserId(buf.GetWriteBuf(maxLoginLen), maxLoginLen);
+    buf.UngetWriteBuf();
+
+    if ( !ok )
+        buf.Empty();
+
+    return buf;
 }
 
-bool wxGetHostName(wxString& buf)
+wxString wxGetUserName()
+{
+    static const int maxUserNameLen = 1024; // FIXME arbitrary number
+
+    wxString buf;
+    bool ok = wxGetUserName(buf.GetWriteBuf(maxUserNameLen), maxUserNameLen);
+    buf.UngetWriteBuf();
+
+    if ( !ok )
+        buf.Empty();
+
+    return buf;
+}
+
+wxString wxGetHostName()
 {
     static const size_t hostnameSize = 257;
+
+    wxString buf;
     bool ok = wxGetHostName(buf.GetWriteBuf(hostnameSize), hostnameSize);
 
     buf.UngetWriteBuf();
 
-    return ok;
+    if ( !ok )
+        buf.Empty();
+
+    return buf;
 }