Author: egon
Date: 2004-10-12 10:54:19 -0400 (Tue, 12 Oct 2004)
New Revision: 397
Added:
trunk/clients/wxhaver/src/wxHaverWindows.cpp
trunk/clients/wxhaver/src/wxHaverWindows.h
Modified:
trunk/clients/wxhaver/src/wxHaverFrame.cpp
trunk/clients/wxhaver/src/wxHaverFrame.h
trunk/clients/wxhaver/src/wxHaverParser.cpp
trunk/clients/wxhaver/src/wxHaverParser.h
Log:
Added various nice GUI wrapper things, mainly for the tabs.
Added various miscellaeneous classes.
Modified: trunk/clients/wxhaver/src/wxHaverFrame.cpp
===================================================================
--- trunk/clients/wxhaver/src/wxHaverFrame.cpp 2004-10-12 11:14:22 UTC (rev
396)
+++ trunk/clients/wxhaver/src/wxHaverFrame.cpp 2004-10-12 14:54:19 UTC (rev
397)
@@ -24,6 +24,7 @@
#include "wxHaverFrame.h"
#include "wxHaverParser.h"
+#include "wxHaverWindows.h"
#include "wx/socket.h"
#include <vector>
#include <map>
@@ -37,6 +38,7 @@
wxHaverFrame::OnSashPosChanged)
EVT_SIZE(wxHaverFrame::OnSize)
EVT_SOCKET(WH_Socket, wxHaverFrame::OnSocketEvent)
+ EVT_TEXT_ENTER(-1, wxHaverFrame::OnEnterCommand)
END_EVENT_TABLE()
wxHaverFrame::wxHaverFrame(const wxString &title, const wxPoint &pos,
@@ -64,10 +66,11 @@
mServerSplit = new wxSplitterWindow(this, WH_CTRL_ServerSplitter,
wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE);
- mTextEntry = new wxTextCtrl(this, -1);
+ mTextEntry = new wxTextCtrl(this, -1, _(""), wxDefaultPosition,
+ wxDefaultSize, wxTE_PROCESS_ENTER);
- mChannels = new wxNotebook(mServerSplit, -1);
- mUserList = new wxListBox(mServerSplit, -1);
+ mChannels = new wxHaverWindows(mServerSplit, mSock);
+ mUserList = new wxListBox(mServerSplit, -1);
//---------------------------//
// Miscellaeneous //
@@ -88,26 +91,28 @@
topsizer->Add(mTextEntry, 0, wxGROW|wxEXPAND);
this->SetSizer(topsizer);
-
- wxPanel *panel = new wxPanel(mChannels, -1);
- mTextLines = new wxTextCtrl(panel, -1, "", wxDefaultPosition,
- wxDefaultSize, wxTE_MULTILINE);
- wxBoxSizer *panelsizer = new wxBoxSizer(wxVERTICAL);
- panelsizer->Add(mTextLines, 1, wxEXPAND);
- panel->SetSizer(panelsizer);
- mChannels->AddPage(panel, "[Server]");
- mTextLines->SetEditable(false);
+ mChannels->NewWindow("[Server]");
+ mServer = mChannels->Window("[Server]");
//---------------------------//
- // Socket stuff //
+ // Command stuff //
//---------------------------//
+ // {Server Commands}
wxHaverCallback<wxHaverFrame> *want;
want = new wxHaverCallback<wxHaverFrame>(this, &wxHaverFrame::OnWant);
mParser.AddCommand("WANT", want);
+
+ // {Client Commands}
+/* wxHaverCallback<wxHaverFrame> *join;
+ join = new wxHaverCallback<wxHaverFrame>;*/
+ //---------------------------//
+ // Socket stuff //
+ //---------------------------//
+
mSock = new wxHaverSockClient();
mSock->SetEventHandler(*this, WH_Socket);
mSock->SetNotify(wxSOCKET_CONNECTION_FLAG | wxSOCKET_INPUT_FLAG |
@@ -135,17 +140,17 @@
void wxHaverFrame::OnSocketEvent(wxSocketEvent &event)
{
- *mTextLines << "\nSocketEvent received: ";
+ *mServer << "\nSocketEvent received: ";
switch (event.GetSocketEvent())
{
case wxSOCKET_INPUT:
- *mTextLines << "wxSOCKET_INPUT"; break;
+ *mServer << "wxSOCKET_INPUT"; break;
case wxSOCKET_OUTPUT:
- *mTextLines << "wxSOCKET_OUTPUT"; break;
+ *mServer << "wxSOCKET_OUTPUT"; break;
case wxSOCKET_CONNECTION:
- *mTextLines << "wxSOCKET_CONNECTION"; break;
+ *mServer << "wxSOCKET_CONNECTION"; break;
case wxSOCKET_LOST:
- *mTextLines << "wxSOCKET_LOST"; break;
+ *mServer << "wxSOCKET_LOST"; break;
}
if (event.GetSocketEvent() == wxSOCKET_INPUT) {
// TODO: Write a better line handler, with buffering.
@@ -156,7 +161,7 @@
for (;;) {
line = mBuf.BeforeFirst('\n');
if (line == mBuf) break;
- mTextLines->AppendText(_T("\n(raw) ") + line);
+ mServer->AppendText(_T("\n(raw) ") + line);
printf("line: %s\n", line.c_str());
mParser.Parse(line);
mBuf = mBuf.AfterFirst('\n');
@@ -170,15 +175,15 @@
addr.Hostname("localhost");
addr.Service(7070);
- mTextLines->AppendText(_T("\nConnecting to ") + addr.Hostname() +
_("..."));
+ mServer->AppendText(_T("\nConnecting to ") + addr.Hostname() +
_("..."));
mSock->Connect(addr, false);
mSock->WaitOnConnect(10);
if (mSock->IsConnected())
- mTextLines->AppendText(_T("\nSuccess. Connection
established."));
+ mServer->AppendText(_T("\nSuccess. Connection established."));
else {
mSock->Close();
- mTextLines->AppendText(_T("\nFailed. Unable to connect."));
+ mServer->AppendText(_T("\nFailed. Unable to connect."));
wxString errortext;
errortext << "Could not connect to " << addr.Hostname() <<
" on port " << addr.Service();
@@ -188,8 +193,14 @@
*mSock << "HAVER" << "wxHaver/" WH_VERSION_STRING << CRLF;
}
-void wxHaverFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
+void wxHaverFrame::OnEnterCommand(wxCommandEvent&)
{
+ wxString cmd = mTextEntry->GetLineText(0);
+ mUserParser.Parse(cmd);
+}
+
+void wxHaverFrame::OnQuit(wxCommandEvent&)
+{
Close(true);
}
@@ -199,7 +210,7 @@
void wxHaverFrame::OnWant(vector<wxString> args)
{
- *mTextLines << "\nReceived WANT...";
+ *mServer << "\nReceived WANT...";
if (args[0] == "IDENT") {
*mSock << "IDENT" << "nornagon" << CRLF;
}
Modified: trunk/clients/wxhaver/src/wxHaverFrame.h
===================================================================
--- trunk/clients/wxhaver/src/wxHaverFrame.h 2004-10-12 11:14:22 UTC (rev
396)
+++ trunk/clients/wxhaver/src/wxHaverFrame.h 2004-10-12 14:54:19 UTC (rev
397)
@@ -23,6 +23,7 @@
#include "wxHaver.h"
#include "wxHaverParser.h"
+#include "wxHaverWindows.h"
#include "wx/splitter.h"
#include "wx/socket.h"
@@ -42,18 +43,19 @@
void OnSize(wxSizeEvent&);
void OnSashPosChanged(wxSplitterEvent&);
-
void OnSocketEvent(wxSocketEvent&);
+ void OnEnterCommand(wxCommandEvent&);
void OnWant(std::vector<wxString>);
private:
wxHaverSockClient *mSock;
wxSplitterWindow *mServerSplit;
- wxNotebook *mChannels;
- wxTextCtrl *mTextLines;
+ wxHaverWindows *mChannels;
wxTextCtrl *mTextEntry;
+ wxTextCtrl *mServer;
wxListBox *mUserList;
wxHaverParser mParser;
+ wxHaverUserParser mUserParser;
wxString mBuf;
int _splitSize;
Modified: trunk/clients/wxhaver/src/wxHaverParser.cpp
===================================================================
--- trunk/clients/wxhaver/src/wxHaverParser.cpp 2004-10-12 11:14:22 UTC (rev
396)
+++ trunk/clients/wxhaver/src/wxHaverParser.cpp 2004-10-12 14:54:19 UTC (rev
397)
@@ -33,12 +33,17 @@
line.Remove(line.find('\r'), 1);
}
-vector<wxString> Split(wxString line, wxString splitby)
+vector<wxString> Split(wxString line, wxString splitby, unsigned int limit)
{
printf("Splitting \"%s\" by \"%s\"\n", line.c_str(), splitby.c_str());
size_t tp;
vector<wxString> tokens;
+ int i = 1;
while ((tp = line.find(splitby))) {
+ if (limit) {
+ if (i >= limit) break;
+ i++;
+ }
if (tp == wxString::npos) break;
tokens.push_back(line.substr(0, tp));
line.erase(0, tp+1);
@@ -80,6 +85,11 @@
// TODO: Add default commands?
}
+wxHaverParser::~wxHaverParser()
+{
+ // FIXME: delete things
+}
+
int wxHaverParser::AddCommand(wxString cmdname, wxHaverFunctor *callback)
{
_commands[cmdname] = callback;
@@ -107,5 +117,24 @@
wxString command = cmd[0];
cmd.erase(cmd.begin());
(*_commands[command])(cmd);
+ return;
}
+//------------------------------------------------------------------------
+// wxHaverUserParser : wxHaverParser
+//------------------------------------------------------------------------
+
+void wxHaverUserParser::Parse(wxString line)
+{
+ printf("User did \"%s\"\n", line.c_str());
+ vector<wxString> cmd = Split(line, " ", 2);
+ if (_commands.find(cmd[0]) == _commands.end()) {
+ printf("User command %s doesn't exist\n", cmd[0].c_str());
+ return;
+ }
+ printf("User command exists\n");
+ wxString command = cmd[0];
+ cmd.erase(cmd.begin());
+ (*_commands[command])(cmd);
+ return;
+}
Modified: trunk/clients/wxhaver/src/wxHaverParser.h
===================================================================
--- trunk/clients/wxhaver/src/wxHaverParser.h 2004-10-12 11:14:22 UTC (rev
396)
+++ trunk/clients/wxhaver/src/wxHaverParser.h 2004-10-12 14:54:19 UTC (rev
397)
@@ -39,7 +39,8 @@
inline void Strip(wxString &line);
// Split one wxString by another.
-std::vector<wxString> Split(wxString line, wxString splitby = "\t");
+std::vector<wxString> Split(wxString line, wxString splitby = "\t",
+ unsigned int limit = 0);
// Splice a bunch of wxStrings together with splicewith.
wxString Splice(std::vector<wxString> tokens, wxString splicewidth = "\t");
@@ -55,7 +56,10 @@
{
private:
void (T::*fpt)(std::vector<wxString>);
- // XXX: This causes spurrious compiler errors. Why?
+ // XXX: This causes spurious compiler errors. Why?
+ // JA> I have no idea. It seems to work fine for me (mingw32)
+ // Of course, that's probably because I don't tell my
compiler
+ // to tell me off with its -Wallness. :)
T* pt2Obj;
public:
wxHaverCallback(T *_pt2Obj,
void(T::*_fpt)(std::vector<wxString>)):
@@ -74,11 +78,18 @@
{
public:
wxHaverParser();
- int AddCommand(wxString cmdname, wxHaverFunctor *callback);
- int DelCommand(wxString cmdname);
- void Parse(wxString line);
- private:
+ virtual ~wxHaverParser();
+ virtual int AddCommand(wxString cmdname, wxHaverFunctor
*callback);
+ virtual int DelCommand(wxString cmdname);
+ virtual void Parse(wxString line);
+ protected:
std::map<wxString, wxHaverFunctor*> _commands;
};
+class wxHaverUserParser : public wxHaverParser
+{
+ public:
+ void Parse(wxString line);
+};
+
#endif // WH_wxHaverParser_H
Added: trunk/clients/wxhaver/src/wxHaverWindows.cpp
===================================================================
--- trunk/clients/wxhaver/src/wxHaverWindows.cpp 2004-10-12 11:14:22 UTC
(rev 396)
+++ trunk/clients/wxhaver/src/wxHaverWindows.cpp 2004-10-12 14:54:19 UTC
(rev 397)
@@ -0,0 +1,102 @@
+/* vim: set ft=cpp ts=4 sw=4:
+ * wxHaver - A client for the Haver chat system that utilises wxWindows.
+ *
+ * Copyright (C) 2004 Jeremy Cambell Apthorp.
+ *
+ * This software is free; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty if
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Puvlic License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "wxHaver.h"
+#include "wx/notebook.h"
+#include "wxHaverWindows.h"
+#include "wxHaverParser.h"
+
+//------------------------------------------------------------------------
+// wxHaverWindows
+//------------------------------------------------------------------------
+
+wxHaverWindows::wxHaverWindows(wxWindow *parent, wxWindowID id,
+ const wxPoint &pos, const wxSize &size,
+ long style, const wxString &name):
+ wxNotebook(parent, id, pos, size, style, name)
+{}
+
+wxHaverWindows::wxHaverWindows(wxWindow *parent, wxHaverSockClient *sock,
+ wxWindowID id):
+ wxNotebook(parent, id), _sock(sock)
+{}
+
+wxHaverWindows::~wxHaverWindows()
+{
+ DeleteAllPages();
+}
+
+void wxHaverWindows::SetSock(wxHaverSockClient *sock) { _sock = sock; }
+
+void wxHaverWindows::NewWindow(wxString title)
+{
+ Page *page = new Page;
+ wxPanel *panel = new wxPanel(this, -1);
+ wxBoxSizer *panelsizer = new wxBoxSizer(wxVERTICAL);
+ wxTextCtrl *txt = new wxTextCtrl(panel, -1, "", wxDefaultPosition,
+ wxDefaultSize, wxTE_MULTILINE);
+ txt->SetEditable(false);
+ panelsizer->Add(txt, 1, wxEXPAND);
+ panel->SetSizer(panelsizer);
+ page->window = panel;
+ page->text = txt;
+ windows[title] = page;
+ AddPage(panel, title);
+}
+
+void wxHaverWindows::DelWindow(wxString title)
+{
+ for (int i = 0; i < GetPageCount(); i++)
+ if (GetPageText(i) == title) { DeletePage(i); break; }
+}
+
+int wxHaverWindows::Join(wxString cid)
+{
+ *_sock << "JOIN" << cid << CRLF;
+ NewWindow(cid);
+ return 0;
+}
+
+int wxHaverWindows::Query(wxString uid)
+{
+ return 0;
+}
+
+int wxHaverWindows::Close(wxString window)
+{
+ DelWindow(window);
+ return 0;
+}
+
+int wxHaverWindows::Part(wxString cid)
+{
+ *_sock << "PART" << cid << CRLF;
+ DelWindow(cid);
+ return 0;
+}
+
+void wxHaverWindows::Message(wxString id, wxString message)
+{
+}
+
+wxTextCtrl *wxHaverWindows::Window(wxString id)
+{
+ return windows[id]->text;
+}
Property changes on: trunk/clients/wxhaver/src/wxHaverWindows.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/clients/wxhaver/src/wxHaverWindows.h
===================================================================
--- trunk/clients/wxhaver/src/wxHaverWindows.h 2004-10-12 11:14:22 UTC (rev
396)
+++ trunk/clients/wxhaver/src/wxHaverWindows.h 2004-10-12 14:54:19 UTC (rev
397)
@@ -0,0 +1,57 @@
+/* vim: set ft=cpp ts=4 sw=4:
+ * wxHaver - A client for the Haver chat system that utilises wxWindows.
+ *
+ * Copyright (C) 2004 Jeremy Cambell Apthorp.
+ *
+ * This software is free; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty if
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Puvlic License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef WH_wxHaverWindows_H
+#define WH_wxHaverWindows_H
+
+#include "wxHaver.h"
+#include "wxHaverParser.h"
+#include "wx/notebook.h"
+#include <map>
+
+class wxHaverWindows : public wxNotebook
+{
+ public:
+ wxHaverWindows(wxWindow *parent, wxWindowID id = -1,
+ const wxPoint &pos = wxDefaultPosition,
+ const wxSize &size = wxDefaultSize,
+ long style = 0, const wxString &name =
"notebook");
+ wxHaverWindows(wxWindow *parent, wxHaverSockClient *sock,
+ wxWindowID id = -1);
+ ~wxHaverWindows();
+ struct Page {
+ wxWindow *window;
+ wxTextCtrl *text;
+ };
+ void SetSock(wxHaverSockClient *sock);
+ void NewWindow(wxString title);
+ int Join(wxString cid);
+ int Query(wxString uid);
+ int Close(wxString window);
+ int Part(wxString cid);
+ void Message(wxString id, wxString message);
+ wxTextCtrl *Window(wxString id);
+ private:
+ void DelWindow(wxString title);
+ wxHaverSockClient *_sock;
+ std::map<wxString, Page*> windows;
+};
+
+#endif // WH_wxHaverWindows_H
Property changes on: trunk/clients/wxhaver/src/wxHaverWindows.h
___________________________________________________________________
Name: svn:eol-style
+ native