Author: egon
Date: 2004-10-11 04:09:42 -0400 (Mon, 11 Oct 2004)
New Revision: 375

Modified:
   trunk/clients/wxhaver/wxHaverFrame.cpp
Log:
Fixed wxHaverFrame.cpp conflict, updated wxHaverFrame.cpp

Modified: trunk/clients/wxhaver/wxHaverFrame.cpp
===================================================================
--- trunk/clients/wxhaver/wxHaverFrame.cpp      2004-10-10 21:50:35 UTC (rev 
374)
+++ trunk/clients/wxhaver/wxHaverFrame.cpp      2004-10-11 08:09:42 UTC (rev 
375)
@@ -32,6 +32,139 @@
 
        mServerSplit = new wxSplitterWindow(this, WH_CTRL_ServerSplitter,
                wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE);
+       mTextLines      = new wxTextCtrl(mServerSplit, -1, "", 
wxDefaultPosition,
+                       wxDefaultSize, wxTE_MULTILINE);
+       mTextEntry      = new wxTextCtrl(this, -1);
+       mUserList       = new  wxListBox(mServerSplit, -1);
+
+       wxSize txtsize(mTextEntry->GetSize());
+       wxSize boxsize(mUserList->GetSize());
+       wxSize clientsize(GetClientSize());
+       mTextEntry->SetSize(0, clientsize.y - txtsize.y, clientsize.x, 
txtsize.y);
+       mUserList->SetSize(clientsize.x - 100, 0, 100, clientsize.y - 
txtsize.y);
+       mTextLines->SetSize(0, 0, clientsize.x - 100, clientsize.y - txtsize.y);
+
+       mTextLines->SetEditable(false);
+       mServerSplit->SplitVertically(mTextLines, mUserList, -_splitSize);
+
+       wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
+       topsizer->Add(mServerSplit, 1, wxGROW);
+       topsizer->Add(mTextEntry, 0, wxGROW);
+
+       SetSizer(topsizer);
+
+       mSock = new wxSocketClient();
+       mSock->SetEventHandler(*this, WH_Socket);
+       mSock->SetNotify(wxSOCKET_CONNECTION_FLAG | wxSOCKET_INPUT_FLAG |
+                       wxSOCKET_LOST_FLAG);
+       mSock->Notify(true);
+}
+
+wxHaverFrame::~wxHaverFrame()
+{
+       mSock->Destroy();
+}
+
+void wxHaverFrame::OnSashPosChanged(wxSplitterEvent &event)
+{
+       _splitSize = GetClientSize().GetWidth() - event.GetSashPosition();
+       event.Skip();
+}
+
+void wxHaverFrame::OnSize(wxSizeEvent& event)
+{
+       if (mServerSplit)
+               mServerSplit->SetSashPosition(GetClientSize().GetWidth() - 
_splitSize);
+       event.Skip();
+}
+
+void wxHaverFrame::OnSocketEvent(wxSocketEvent &event)
+{
+       *mTextLines << "\nSocketEvent received.";
+       if (event.GetSocketEvent() == wxSOCKET_INPUT) {
+               // TODO: Write a better line handler, with buffering.
+               *mTextLines << "\nIt's a SOCKET_INPUT";
+               wxChar buf;
+               wxString str;
+               int gotcrlf = -1;
+               
+               for (;;) {
+                       if (buf == '\r')
+                               gotcrlf++;
+                       mSock->Read(&buf, 1);
+                       str += buf;
+                       if (gotcrlf >= 0 && buf == '\n') {
+                               gotcrlf++;
+                               str += buf;
+                               break;
+                       }
+               }
+               
+               mTextLines->AppendText(_T("\n(raw) ") + str);
+       }
+}
+
+void wxHaverFrame::OnConnect(wxCommandEvent& WXUNUSED(event))
+{
+       wxIPV4address addr;
+       addr.Hostname("localhost");
+       addr.Service(7071);
+
+       mTextLines->AppendText(_T("\nConnecting to ") + addr.Hostname() + 
_("..."));
+       mSock->Connect(addr, false);
+       mSock->WaitOnConnect(10);
+       
+       if (mSock->IsConnected())
+               mTextLines->AppendText(_T("\nSuccess. Connection 
established."));
+       else {
+               mSock->Close();
+               mTextLines->AppendText(_T("\nFailed. Unable to connect."));
+               wxString errortext;
+               errortext << "Could not connect to " << addr.Hostname() <<
+                       " on port " << addr.Service();
+               wxMessageBox(errortext, "Alert!");
+       }
+}
+
+void wxHaverFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
+{
+       Close(true);
+}
+
+/* Some default text.
+ */
+
+//------------------------------------------------------------------------
+//  wxHaverFrame
+//------------------------------------------------------------------------
+
+#include "wxHaverFrame.h"
+#include "wx/socket.h"
+
+BEGIN_EVENT_TABLE(wxHaverFrame, wxFrame)
+       EVT_MENU(WH_ID_Quit, wxHaverFrame::OnQuit)
+       EVT_MENU(WH_ID_Connect, wxHaverFrame::OnConnect)
+       EVT_SPLITTER_SASH_POS_CHANGED(WH_CTRL_ServerSplitter,
+                       wxHaverFrame::OnSashPosChanged)
+       EVT_SIZE(wxHaverFrame::OnSize)
+       EVT_SOCKET(WH_Socket, wxHaverFrame::OnSocketEvent)
+END_EVENT_TABLE()
+
+wxHaverFrame::wxHaverFrame(const wxString &title, const wxPoint &pos,
+               const wxSize &size):
+       wxFrame((wxFrame*)NULL, -1, title, pos, size), _splitSize(100)
+{
+       wxMenu *File_menu = new wxMenu;
+       File_menu->Append(WH_ID_Quit, "E&xit");
+       File_menu->Append(WH_ID_Connect, "&Connect");
+
+       wxMenuBar *menuBar = new wxMenuBar;
+       menuBar->Append(File_menu, "&File");
+
+       SetMenuBar(menuBar);
+
+       mServerSplit = new wxSplitterWindow(this, WH_CTRL_ServerSplitter,
+               wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE);
        mTextLines      = new wxTextCtrl(mServerSplit, -1, "", 
wxDefaultPosition, wxDefaultSize,
                        wxTE_MULTILINE);
        mTextEntry      = new wxTextCtrl(this, -1);
@@ -129,4 +262,3 @@
 {
        Close(true);
 }
-


Reply via email to