LFLAGS=`wx-config --libs`
daphne: main.o citclient.o userlogin.o testwindow.o who.o \
- utils.o tcp_sockets.o express_message.o send_express.o
+ utils.o tcp_sockets.o express_message.o send_express.o \
+ roomtree.o
c++ main.o citclient.o userlogin.o testwindow.o who.o \
utils.o tcp_sockets.o express_message.o send_express.o \
+ roomtree.o \
$(LFLAGS) -o daphne
main.o: main.cpp includes.hpp
send_express.o: send_express.cpp includes.hpp
c++ -c $(CFLAGS) send_express.cpp
+
+roomtree.o: roomtree.cpp includes.hpp
+ c++ -c $(CFLAGS) roomtree.cpp
#include <wx/wx.h>
#include <wx/listctrl.h>
#include <wx/socket.h>
-
-
-
-// Globals
-
-extern wxMDIParentFrame *BigMDI;
-extern wxTreeCtrl *RoomList;
-
+#include <wx/log.h>
+#include "wx/imaglist.h"
+#include "wx/treectrl.h"
// TCPsocket represents a socket-level TCP connection to a server.
+// The ever-present tree of floors and rooms
+
+class RoomTree : public wxTreeCtrl {
+public:
+ RoomTree(wxWindow *parent, CitClient *sock);
+ void LoadRoomList(void);
+private:
+ void InitTreeIcons(void);
+ CitClient *citsock;
+ wxTreeItemId floorboards[128];
+ wxImageList *TreeIcons;
+};
+
+
+
+
// Stuff from utils.cpp
void MultilineToList(wxStringList& outputlist, wxString inputbuf);
void extract(wxString& outputbuf, wxString inputbuf, int parmnum);
int extract_int(wxString inputbuf, int parmnum);
-void load_roomlist(wxTreeCtrl *tree, CitClient *citsock);
+void load_roomlist(RoomTree *tree, CitClient *citsock);
+
+// Globals
+
+extern wxMDIParentFrame *BigMDI;
+extern RoomTree *RoomList;
+
+
// Globals
wxMDIParentFrame *BigMDI;
-wxTreeCtrl *RoomList;
+RoomTree *RoomList;
// ----------------------------------------------------------------------------
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnDoCmd(wxCommandEvent& event);
+ void GotoNewRoom(wxTreeEvent& event);
private:
void OnConnect(wxCommandEvent& event);
void OnTestWin(wxCommandEvent& event);
WMENU_ARRANGE,
WMENU_NEXT,
WMENU_PREVIOUS,
- BUTTON_DO_CMD
+ BUTTON_DO_CMD,
+ ROOMTREE_DOUBLECLICK
};
// ----------------------------------------------------------------------------
// Create a new application object: this macro will allow wxWindows to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also declares the accessor function
-// wxGetApp() which will return the reference of the right type (i.e. Daphne and
-// not wxApp)
+// wxGetApp() which will return the reference of the right type (i.e. Daphne
+// and not wxApp)
IMPLEMENT_APP(Daphne)
// ============================================================================
// Set up the left-side thingie
- RoomList = new wxTreeCtrl(
- this, -1,
- wxDefaultPosition, wxDefaultSize,
- wxTR_HAS_BUTTONS | wxSUNKEN_BORDER,
- wxDefaultValidator,
- "RoomList");
+ RoomList = new RoomTree(this, citadel);
wxLayoutConstraints *t2 = new wxLayoutConstraints;
t2->top.SameAs(this, wxTop, 4);
void MyFrame::OnTestWin(wxCommandEvent& unused) {
new TestWindow(citadel, this);
}
+
// FIX ... add code here to perform registration if necessary
- load_roomlist(RoomList, citsock);
+ RoomList->LoadRoomList();
}
// utility functions not belonging to any particular class
-#include <wx/wx.h>
#include "includes.hpp"
-#include "bitmaps/root.xpm"
-#include "bitmaps/floor.xpm"
-#include "bitmaps/newroom.xpm"
-#include "bitmaps/oldroom.xpm"
-#include "bitmaps/mailroom.xpm"
-
-wxTreeItemId floorboards[128];
-wxImageList *TreeIcons = NULL;
-
// The following two functions convert between the wxStringList class used for
// text transfers to and from the Citadel server, and the wxString class used
// for the contents of a wxTextCtrl.
return atoi(buf);
}
-
-void InitTreeIcons(void) {
- TreeIcons = new wxImageList(16, 16);
- TreeIcons->Add(wxICON(root));
- TreeIcons->Add(wxICON(floor));
- TreeIcons->Add(wxICON(newroom));
- TreeIcons->Add(wxICON(oldroom));
- TreeIcons->Add(wxICON(mailroom));
-}
-
-
-// Load a tree with a room list
-//
-void load_roomlist(wxTreeCtrl *tree, CitClient *citsock) {
- wxString sendcmd, recvcmd, buf, floorname, roomname;
- wxStringList transbuf;
- wxTreeItemId item;
- int i, floornum;
-
- if (TreeIcons == NULL) InitTreeIcons();
-
- // First, clear it out.
- tree->DeleteAllItems();
- tree->SetImageList(TreeIcons);
-
- // Set the root with the name of the Citadel server.
- tree->AddRoot(
- citsock->HumanNode,
- 0,
- -1,
- NULL);
-
- sendcmd = "LFLR";
- // Bail out silently if we can't retrieve the floor list
- if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
-
- // Load the floors one by one onto the tree
- for (i=0; i<transbuf.Number(); ++i) {
- buf.Printf("%s", (wxString *)transbuf.Nth(i)->GetData());
- extract(floorname, buf, 1);
- floornum = extract_int(buf, 0);
- floorboards[floornum] = tree->AppendItem(
- tree->GetRootItem(),
- floorname,
- 1,
- -1,
- NULL);
- }
-
- // Load the rooms with new messages into the tree
- sendcmd = "LKRN";
- if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
- for (i=0; i<transbuf.Number(); ++i) {
- buf.Printf("%s", (wxString *)transbuf.Nth(i)->GetData());
- extract(roomname, buf, 0);
- floornum = extract_int(buf, 2);
- item = tree->AppendItem(
- floorboards[floornum],
- roomname,
- 2,
- -1,
- NULL);
- tree->SetItemBold(item, TRUE);
- tree->SetItemBold(floorboards[floornum], TRUE);
- }
-
- // Load the rooms with new messages into the tree
- sendcmd = "LKRO";
- if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
- for (i=0; i<transbuf.Number(); ++i) {
- buf.Printf("%s", (wxString *)transbuf.Nth(i)->GetData());
- extract(roomname, buf, 0);
- floornum = extract_int(buf, 2);
- tree->AppendItem(
- floorboards[floornum],
- roomname,
- 3,
- -1,
- NULL);
- }
-
-}