From: Vadim Zeitlin Date: Fri, 17 Mar 2000 23:00:10 +0000 (+0000) Subject: 1. wxGetFullHostName() does return the full host name now under MSW X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1f0500b3ee1255cc71624bc58b83d0d954b2d45e 1. wxGetFullHostName() does return the full host name now under MSW 2. wxGetEmailAddress() doesn't always return empty string... 3. status bar created under MSW is of type wxStatusBar, hence wxWin RTTI works for it 4. carsh in IPC sample fixed git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6810 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/sckipc.cpp b/src/common/sckipc.cpp index f577b046f3..16406abe08 100644 --- a/src/common/sckipc.cpp +++ b/src/common/sckipc.cpp @@ -409,7 +409,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event) { wxSocketBase *sock = event.GetSocket(); wxSocketNotify evt = event.GetSocketEvent(); - wxTCPConnection *connection = (wxTCPConnection *)(event.GetClientData()); + wxTCPConnection *connection = (wxTCPConnection *)(sock->GetClientData()); // This socket is being deleted; skip this event if (!connection) diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 542adadde6..b2947da8e8 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -1242,7 +1242,7 @@ class WXDLLEXPORT wxSocketModule : public wxModule DECLARE_DYNAMIC_CLASS(wxSocketModule) public: - bool OnInit() { return GSocket_Init(); } + bool OnInit() { return GSocket_Init() != 0; } void OnExit() { GSocket_Cleanup(); } }; diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 2ac002dec3..0eb8453bd6 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -1091,14 +1091,13 @@ wxString wxGetEmailAddress() { wxString email; - wxString host = wxGetHostName(); + wxString host = wxGetFullHostName(); if ( !!host ) { wxString user = wxGetUserId(); if ( !!user ) { - wxString email(user); - email << wxT('@') << host; + email << user << wxT('@') << host; } } diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 4e528223ee..ac077260fa 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -360,30 +360,28 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number, wxStatusBar *statusBar = NULL; #if wxUSE_NATIVE_STATUSBAR - if ( UsesNativeStatusBar() ) + if ( !UsesNativeStatusBar() ) { - statusBar = (wxStatusBar *)new wxStatusBar95(this, id, style); - - statusBar->SetFieldsCount(number); + statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); } else #endif { - statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style, name); + statusBar = new wxStatusBar(this, id, style, name); + } - // Set the height according to the font and the border size - wxClientDC dc(statusBar); - dc.SetFont(statusBar->GetFont()); + // Set the height according to the font and the border size + wxClientDC dc(statusBar); + dc.SetFont(statusBar->GetFont()); - wxCoord y; - dc.GetTextExtent(_T("X"), NULL, &y ); + wxCoord y; + dc.GetTextExtent(_T("X"), NULL, &y ); - int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY()); + int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY()); - statusBar->SetSize(-1, -1, -1, height); + statusBar->SetSize(-1, -1, -1, height); - statusBar->SetFieldsCount(number); - } + statusBar->SetFieldsCount(number); return statusBar; } diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 7126032d69..56413e0523 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -32,12 +32,13 @@ #include "wx/utils.h" #include "wx/app.h" #include "wx/cursor.h" + #include "wx/intl.h" + #include "wx/log.h" #endif //WX_PRECOMP #include "wx/msw/private.h" // includes #include "wx/timer.h" -#include "wx/intl.h" #include @@ -54,14 +55,16 @@ #include #endif //GNUWIN32 -#include "wx/log.h" - #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs // this (3.1 I believe) and how to test for it. // If this works for Borland 4.0 as well, then no worries. #include #endif +#if defined(__WIN32__) && !defined(__TWIN32__) + #include // we use socket functions in wxGetFullHostName() +#endif + // VZ: there is some code using NetXXX() functions to get the full user name: // I don't think it's a good idea because they don't work under Win95 and // seem to return the same as wxGetUserId() under NT. If you really want @@ -146,12 +149,10 @@ static const wxChar eUSERID[] = wxT("UserId"); // get host name and related // ---------------------------------------------------------------------------- -// Get full hostname (eg. DoDo.BSn-Germany.crg.de) +// Get hostname only (without domain name) bool wxGetHostName(wxChar *buf, int maxSize) { #if defined(__WIN32__) && !defined(__TWIN32__) - // TODO should use GetComputerNameEx() when available - DWORD nSize = maxSize; if ( !::GetComputerName(buf, &nSize) ) { @@ -174,8 +175,48 @@ bool wxGetHostName(wxChar *buf, int maxSize) #endif } +// get full hostname (with domain name if possible) bool wxGetFullHostName(wxChar *buf, int maxSize) { +#if defined(__WIN32__) && !defined(__TWIN32__) + // TODO should use GetComputerNameEx() when available + WSADATA wsa; + if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 ) + { + wxString host; + char bufA[256]; + if ( gethostname(bufA, WXSIZEOF(bufA)) == 0 ) + { + // gethostname() won't usually include the DNS domain name, for + // this we need to work a bit more + if ( !strchr(bufA, '.') ) + { + struct hostent *pHostEnt = gethostbyname(bufA); + + if ( pHostEnt ) + { + // Windows will use DNS internally now + pHostEnt = gethostbyaddr(pHostEnt->h_addr, 4, PF_INET); + } + + if ( pHostEnt ) + { + host = pHostEnt->h_name; + } + } + } + + WSACleanup(); + + if ( !!host ) + { + wxStrncpy(buf, host, maxSize); + + return TRUE; + } + } +#endif // Win32 + return wxGetHostName(buf, maxSize); }