Author: egon
Date: 2004-10-10 17:39:49 -0400 (Sun, 10 Oct 2004)
New Revision: 373

Added:
   trunk/clients/wxhaver/wxHaver.cpp
   trunk/clients/wxhaver/wxHaver.h
   trunk/clients/wxhaver/wxHaverFrame.cpp
   trunk/clients/wxhaver/wxHaverFrame.h
Log:


Added: trunk/clients/wxhaver/wxHaver.cpp
===================================================================
--- trunk/clients/wxhaver/wxHaver.cpp   2004-10-10 21:38:29 UTC (rev 372)
+++ trunk/clients/wxhaver/wxHaver.cpp   2004-10-10 21:39:49 UTC (rev 373)
@@ -0,0 +1,25 @@
+/*  wxHaver: A client for the Haver chat system.
+ *  Can someone add licensey things here? I'm no good at them :)
+ */
+
+#include "wxHaver.h"
+
+#include "wx/splitter.h"
+
+class wxHaverApp : public wxApp
+{
+       virtual bool OnInit();
+};
+
+
+bool wxHaverApp::OnInit()
+{
+       wxHaverFrame *frame = new wxHaverFrame("wxHaver/" WH_VERSION_STRING,
+                       wxPoint(-1, -1), wxSize(800, 600));
+       frame->Show(true);
+       SetTopWindow(frame);
+       return true;
+}
+
+IMPLEMENT_APP(wxHaverApp); // I use these semicolons for vim's sake.
+

Added: trunk/clients/wxhaver/wxHaver.h
===================================================================
--- trunk/clients/wxhaver/wxHaver.h     2004-10-10 21:38:29 UTC (rev 372)
+++ trunk/clients/wxhaver/wxHaver.h     2004-10-10 21:39:49 UTC (rev 373)
@@ -0,0 +1,26 @@
+/*  wxHaver: A client for the Haver chat system.
+ *  Can someone add licensey things here? I'm no good at them :)
+ */
+#ifndef WH_wxHaver_H
+#define WH_wxHaver_H
+
+#define WH_VERSION_MAJOR       0
+#define WH_VERSION_MINOR       2
+#define WH_VERSION_STRING      "0.02a"
+
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+#include "wx/wx.h"
+#endif
+
+#include "wxHaverFrame.h"
+
+enum {
+       WH_ID_Quit = 1,
+       WH_ID_Connect,
+       WH_CTRL_ServerSplitter,
+       WH_Socket,
+};
+
+#endif // WH_wxHaver_H

Added: trunk/clients/wxhaver/wxHaverFrame.cpp
===================================================================
--- trunk/clients/wxhaver/wxHaverFrame.cpp      2004-10-10 21:38:29 UTC (rev 
372)
+++ trunk/clients/wxhaver/wxHaverFrame.cpp      2004-10-10 21:39:49 UTC (rev 
373)
@@ -0,0 +1,132 @@
+/* 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);
+       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) {
+               *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);
+}
+

Added: trunk/clients/wxhaver/wxHaverFrame.h
===================================================================
--- trunk/clients/wxhaver/wxHaverFrame.h        2004-10-10 21:38:29 UTC (rev 
372)
+++ trunk/clients/wxhaver/wxHaverFrame.h        2004-10-10 21:39:49 UTC (rev 
373)
@@ -0,0 +1,40 @@
+/* Some default text.
+ *
+ * The wxHaverFrame class interface.
+ */
+
+#ifndef WH_wxHaverFrame_H
+#define WH_wxHaverFrame_H
+
+#include "wxHaver.h"
+
+#include "wx/splitter.h"
+#include "wx/socket.h"
+
+class wxHaverFrame : public wxFrame
+{
+       public:
+               wxHaverFrame(const wxString &title,
+                               const wxPoint &pos,
+                               const wxSize &size);
+               ~wxHaverFrame();
+
+               void OnQuit(wxCommandEvent&);
+               void OnConnect(wxCommandEvent&);
+               
+               void OnSize(wxSizeEvent&);
+               void OnSashPosChanged(wxSplitterEvent&);
+
+               void OnSocketEvent(wxSocketEvent&);
+       private:
+               wxSocketClient *mSock;
+               wxSplitterWindow *mServerSplit;
+               wxTextCtrl      *mTextLines;
+               wxTextCtrl      *mTextEntry;
+               wxListBox       *mUserList;
+               int _splitSize;
+
+       DECLARE_EVENT_TABLE()
+};
+
+#endif // WH_wxHaverFrame_H


Reply via email to